brown2005 Posted July 19, 2006 Share Posted July 19, 2006 Hi, say my birthdate is 30/03/1983.wat i want to do is use a function to say my next birthday is 30/03/2007 (cause my birthday has already gone, so it will be next year) and that i will be 24..any help please? Quote Link to comment Share on other sites More sharing options...
Joe Haley Posted July 19, 2006 Share Posted July 19, 2006 Simple: Check if the date has alredy passed this year, if not, say its 30/03 this year. Otherwise, 30/03 next year.http://php.net/manual/en/function.date.phpThe problem comes with leap year birthdays. Simply doing it that way without checking for a leap year birthday would ocasionally tell ya someone has a birthday on a day that doesnt exist! Quote Link to comment Share on other sites More sharing options...
brown2005 Posted July 19, 2006 Author Share Posted July 19, 2006 thats, exactly wat I thought, but I just wondered if one of the brainy people on here that have more expierence than me had ever written a function for this... Quote Link to comment Share on other sites More sharing options...
chrisprse Posted July 19, 2006 Share Posted July 19, 2006 [code=php:0]<?php$birthday_day = 30;$birthday_month = 3;$birthday_year = 1983;$today_day = date("j");$today_month = date("n");$today_year = date("Y");$next_year = date("Y") + 1;$age = $today_year - $birthday_year;if($today_month <= $birthday_month) { if($today_month == $birthday_month) { if($birthday_day > $today_day) { $age--; echo "Your next birthday is on ".$birthday_day." ".$birthday_month." ".$today_year.""; } else { echo "Your next birthday is on ".$birthday_day." ".$birthday_month." ".$next_year.""; } } else { echo "Your next birthday is on ".$birthday_day." ".$birthday_month." ".$today_year.""; }}else { echo "Your next birthday is on ".$birthday_day." ".$birthday_month." ".$next_year."";}$age++;echo "You will be ".$age." on your next birthday...";?>[/code] Quote Link to comment Share on other sites More sharing options...
brown2005 Posted July 19, 2006 Author Share Posted July 19, 2006 cheers thats cool... so does that work for leap years n everything...? and how can i output the next birthday... i.e. 30th March 2007 Quote Link to comment Share on other sites More sharing options...
chrisprse Posted July 19, 2006 Share Posted July 19, 2006 Edited to show next birthdays... It should work for leap years also, although I haven't tried. Let me know if it doesn't and I will have another look for you Quote Link to comment Share on other sites More sharing options...
chrisprse Posted July 19, 2006 Share Posted July 19, 2006 On a side note, if you enter the following underneath the "$birthday_" variables:[code=php:0]if(($birthday_day == 29) && ($birthday_month == 2)) {$birthday_day = 28;}[/code]This will change their birthday day to 28th Feb as you will find many people born on 29th Feb will celebrate their birthday on 28th Feb...hth Quote Link to comment Share on other sites More sharing options...
brown2005 Posted July 19, 2006 Author Share Posted July 19, 2006 nice one mate..thanks for all your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.