Jump to content

[SOLVED] how to subtract dates to get age?


ted_chou12

Recommended Posts

here's an approximation. The months is not going to be 100%. Someone has something better somewhere, you might have to dig.

[code]<?php
$date="12 March 1983";
$total=time()-strtotime($date);
$calc=array('years'=>60*60*24*365, 'months'=>60*60*24*30,'days'=>60*60*24,'hours'=>60*60,'minutes'=>60);
do {
if(current($calc)<$total) {
echo floor($total/current($calc))." ".key($calc)."<br />\n";
$total=$total - floor($total/current($calc))*current($calc);
}
}while(next($calc));

?>[/code]

Archived

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

×
×
  • Create New...

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.