From: "Ryan A" <[EMAIL PROTECTED]>
> Theres a "date_of_birth" field there that has the values in this format
> YYYY-MM-DD, the client wants me to
> print out the age of the person from that...looking in the manual
> (http://se.php.net/manual/en/function.date.php)
> I think I will need to use mktime....but how??
Assuming you mean a database field, you can do this in your query to get the
age:
SELECT YEAR(CURRENT_DATE) -YEAR(dob) -
(IF(DAYOFYEAR(dob)>DAYOFYEAR(CURRENT_DATE),1,0)) AS age FROM table ...
Where "dob" is the date of birth column.
You could do the same thing in PHP by using strtotime() on the YYYY-MM-DD
formatted date to get a Unix timestamp. Then either subtract that from the
current timestamp and do the division to figure out years, or use something
like the above query. date('Y',$current) - date('Y',$dob), then subtract one
if the birthday day of year hasn't arrived yet.
I'm sure there are a host of other ways, too.
---John Holmes...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php