Re: subtracting dates...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Try this (taken from http://us2.php.net/manual/en/ref.datetime.php):

*menaurus at gmx dot de*
16-Jul-2003 02:37 	
|The argument has to be in the standard mysql format (y-m-d)...

function age($date) {

if (!$date) return false;
$year=0+substr($date,0,4);
$month=0+substr($date,5,2);
$day=0+substr($date,8,2);
$t=0;
$d=date("d");
$m=date("m");
$y=date("Y");
$age=$y-$year;

|if ($month<$m) $t=-1;
else if ($m==$month AND $day<$d) $t=-1;|||

return ($age+$t);
}
|


Good luck.


--Dave

John Ryan wrote:

Hi,

In mySQL, I store dates as YYYY-MM-DD, a standard DATE type. It stores users
date of births. I need to calculate in a PHP script, the users age from this
DOB. I get a PHP date in the same format as the mySQL and subtract, which
returns the year rounded off. ie, it doesnt matter if your birthdays in june
of 1983 and the date is januray 2003, your age is still returned as 20, when
it should be 19.

Does anyone know how can i get the right age?








-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux