note 41358 deleted from function.date by tomsommer
| From: | tomsommer@php.net | Date: | Thu, 08 Apr 2004 00:38:57 +0000 |
| Subject: | note 41358 deleted from function.date by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67792@lists.php.net to get a copy of this message | ||
Note Submitter: jwhiskers_@hotmail.com
----
I spent ages looking for something that did this but couldn't find anything useful, so here is
my stab at a date difference function.
This function will return the number of years, months and days between two timestamps.
It's not heavily tested but should be about right!
function DateDiff( $start, $end )
{
$months = -1;
$days = floor( ( $end - $start ) / 86400 );
$current = $start;
while( $current < $end )
{
$months++;
if( $current != $start )
$days -= date( "t", $current );
else
$days -= ( date( "t", $current ) - date( "d", $start ) );
$current = strtotime( "+1 month", $current );
}
$years = floor( $months / 12 );
$months = $months % 12;
$result[ "years" ] = $years;
$result[ "months" ] = $months;
$result[ "days" ] = $days;
return $result;
}