note 41381 added to function.mktime
| From: | MarkV at rn2 dot php dot net | Date: | Thu, 08 Apr 2004 03:44:27 +0000 |
| Subject: | note 41381 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67797@lists.php.net to get a copy of this message | ||
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)));
}
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41381
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41381&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41381&report=yes
Search -- http://master.php.net/manage/user-notes.php