note 41954 deleted from function.date by tomsommer
| From: | tomsommer@php.net | Date: | Tue, 27 Apr 2004 17:15:51 +0000 |
| Subject: | note 41954 deleted from function.date by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-68893@lists.php.net to get a copy of this message | ||
Note Submitter: php at moechofe dot com
----
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 ) ); }
?>