note 41954 added to function.date
| From: | phpatmoechofedotcom at rn2 dot php dot net | Date: | Tue, 27 Apr 2004 16:36:29 +0000 |
| Subject: | note 41954 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68892@lists.php.net to get a copy of this message | ||
this function try to calculate the different between two dates in YYYY-MM-DD HH:MM:SS format and
return the result in the same format.
<?php
function date_difference( $date1, $date2 ) { return sprintf( '%04d', max( 0, intval(
date( 'Y', $date = ( ( $date1 = strtotime( $date1 ) ) < ( $date2 = strtotime( $date2
) ) ) ? $date2 - $date1 : $date1 - $date2 ) ) - 1970 ) ) . '-'.sprintf( '%02d',
max( 0, intval( date( 'm', $date ) ) - 1 ) ) . '-'.sprintf( '%02d',
max( 0, intval( date( 'd', $date ) ) - 1 ) ) . ' '.sprintf( '%02d',
max( 0, intval( date( 'G', $date ) ) - 1 ) ) . ':'.( date( 'i:s',
$date ) ); }
?>
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41954
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41954&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41954&report=yes
Search -- http://master.php.net/manage/user-notes.php