PDA

View Full Version : Age script needed


SWBreeze
28-01-2006, 17:27
I want to add a script to a webpage that shows age in years, months, days. I used to have one, but lost it and I've just spent ages looking for one but have given up.

Anyone know a simple code I can use for this, php would probably be best

Thanks

Vex
28-01-2006, 17:43
Quickly wrote this:

<?PHP

$birthday = "1980-01-28 00:00:00";

$difference = time() - strtotime($birthday); # In seconds

$years = floor($difference / 31556926);

$temp = $difference - ($years * 31556926);
$months = floor($temp / 2629743.83);

$temp = $temp - ($months * 2629743.83);
$days = floor($temp / 86400);

echo "Age is ".$years." years, ".$months." months, ".$days." days.";

?>


Not entirely sure how accurate it is... As month length varies....

It's a start anyhow.. :)