Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

DOB Calculations...

Recommended Posts

Hi,
I was wondering how to get a date of birth from a database and calculate it/the year to output an age.
ie: 01/02/1990 - 16 | 01/02/1989 - 17.
but make PHP calculate it.

Share this post


Link to post
Share on other sites
I might have gone at this the long way around, but hey, it works...
[code]<?php
function age($dob) {
$date = strtotime($dob);
$today = strtotime(date("d/m/Y"));
echo floor(($today - $date) / 31556926);
}

age("16/12/1985"); //Displays 20
?>[/code]

Share this post


Link to post
Share on other sites
thanks :] if it works it doesn't matter how long it is really.

Share this post


Link to post
Share on other sites
Looking back on my solution, it's not a very good one, as unix time stamps only start from 01/01/1970 and Negative timestamps are only available on PHP5 and on some *NIX based OS

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.