Re: x years old
| From: | Matthew Weier O'Phinney | Date: | Sun, 03 Jul 2005 03:34:45 +0000 |
| Subject: | Re: x years old | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-218042@lists.php.net to get a copy of this message | ||
* "Ryan A" <ryan@coinpass.com>:
> 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/