Calculating age from DOB:php
$age = strtotime(date("Y-m-d")) - strtotime($dob);
$age = round( $age/30758400);
Powered by ScribeFire.
sharing some tech problems and soln
$age = strtotime(date("Y-m-d")) - strtotime($dob);
$age = round( $age/30758400);
Powered by ScribeFire.
Posted by Sajjad at 11:40 am
Thanks, this is very very useful.
ReplyDeleteI <3 you
ReplyDeletehow did you arrive at your magic number of 30758400 ?
ReplyDeleteit looks like you need the number of seconds in a year (avg)
and it looks like you multiplied seconds(60) x minutes(60) x hours(24) x 356 days ??
there are usually 365 days in a year (on earth at least) and 365.25 would be better to describe leap years.
from this i got... 31557600
another solution.. [ from php.net]
ReplyDelete$dob = '1984-09-04';
$age = date('Y') - date('Y', strtotime($dob));
if (date('md') < date('md', strtotime($dob))) {
$age--;
}
Subhankar
http://aafter.com