note 41358 added to function.date
| From: | jwhiskers_ at hotmail dot com | Date: | Wed, 07 Apr 2004 13:46:58 +0000 |
| Subject: | note 41358 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67767@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41358
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41358&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41358&report=yes
Search -- http://master.php.net/manage/user-notes.php