Forum Moderators: coopster

Message Too Old, No Replies

Birthday's in php

Letting users enter a birthday, and displaying their age.

         

nfs2

7:48 pm on Mar 14, 2006 (gmt 0)

10+ Year Member



Whats the best way to let my members enter a birthday, and displaying their age?

At first i thought this would be simple.. maybe it is and im just tired.. But i mean, if i have a table called "birthdays" and one column would be the date and another would be a username.. How would i allow them to enter the date so that i could return an age?

henry0

8:03 pm on Mar 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you seek B-Day date in order to send a Happy B-day
you do not need the age, many do not like to be reminded about their age :)

Just enter a day and a month
then you could have a cron job that daily will pull the B-day compares with today's date and triggers a whishing script.

nfs2

8:07 pm on Mar 14, 2006 (gmt 0)

10+ Year Member



No its not for that, its a community site and i need the age for the profile page im making :)

henry0

8:24 pm on Mar 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



not mine, comes with no refund!
format: birthday ("1935-07-28");
<<<
<?php

//calculate years of age (input string: YYYY-MM-DD)
function birthday ($birthday){
list($year,$month,$day) = explode("-",$birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($day_diff < 0 ¦¦ $month_diff < 0)
$year_diff--;
return $year_diff;
}

?>

>>>

nfs2

8:36 pm on Mar 14, 2006 (gmt 0)

10+ Year Member



Awesome, i'll try it out

Thanks =)