php - mysql mod function return negative number -


great example issue calculate remaining days birthday

i using datediff(currdate(),"birthday column") function , receive days difference , need mod 365.

mod 365 retrieving 364 if contact had birthday yesterday.

datediff(currdate(),currdate() - interval 1 day)= -1
mod(-1,365) = -1

:\ wired!

i find solution issue

mod(mod(negative,365)+365),365)

use `test`; drop procedure if exists `get_user_contacts`;  delimiter $$ use `test`$$  create procedure `test`.`get_user_contacts` (user_id int(11),lim int(11)) begin  declare is_user_exist int(11); select count(*) is_user_exist users `users`.`id` = user_id;     if is_user_exist =1         select `contacts`.*,mod(mod(datediff(curdate(),`contacts`.`birthday` + interval (extract(year curdate())-extract(year `contacts`.`birthday`)) year)*(-1),365)+365,365) diffdate  contacts         left join contacts_users on `contacts`.`id` = `contacts_users`.`contact_id`         left join users on `contacts_users`.`user_id`  = `users`.`id` limit lim;     else select 404 error_number,'user not found.' message;      end if; end$$  delimiter ; 

good luck!


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -