note 41381 deleted from function.mktime by tomsommer
| From: | tomsommer@php.net | Date: | Sun, 07 Nov 2004 20:28:43 +0000 |
| Subject: | note 41381 deleted from function.mktime by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80246@lists.php.net to get a copy of this message | ||
Note Submitter: Mark V
----
This is an update of one of the suggestions above.
This one returns a Negatave Value if date 1 is > date 2
#########################
# date_diff Function
#########################
#
# Calculate the difference between 2 dates in YYYY-MM-DD format.
# Returns the number of days difference.
function date_diff($date1, $date2)
{
//$date1 today, or any other day
//$date2 date to check against
$d1 = explode("-", $date1);
$y1 = $d1[0];
$m1 = $d1[1];
$d1 = $d1[2];
$d2 = explode("-", $date2);
$y2 = $d2[0];
$m2 = $d2[1];
$d2 = $d2[2];
$date1_set = mktime(0,0,0, $m1, $d1, $y1);
$date2_set = mktime(0,0,0, $m2, $d2, $y2);
return(round(($date2_set-$date1_set)/(60*60*24)));
}