Re: x years old

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

 



* "Ryan A" <ryan@xxxxxxxxxxxx>:
> This is the code I am using to display a persons age from the mysql db:
>
> $day1=strtotime($age);
> $day2 = strtotime(date("Y-m-d"));

Just to be pedantic... just use time() for the above statement; no
reason to do extra work here. (date() will actually call time() anyways)

> $dif_s = ($day2-$day1);
> $dif_d = ($dif_s/60/60/24);
> $age = round(($dif_d/365.24));

And, as someone else mentioned, you want to do floor() here, as somebody
is 16 until their 17th birthday.

-- 
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux