note 43091 added to function.mktime
| From: | gustavatmonosevendotcom at rn2 dot php dot net | Date: | Wed, 09 Jun 2004 14:04:09 +0000 |
| Subject: | note 43091 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70552@lists.php.net to get a copy of this message | ||
Modified shadow2day's script. Returns the difference between two given dates in seconds,
minutes, hours or days. And now it also works :)
<?php
// Get date difference between two given dates
// $returntype: s = seconds, m = minutes, h = hours, d = days
// int date_diff(int start_date, int end_date[, string return_type])
function date_diff($start_date, $end_date, $returntype="d")
{
if ($returntype == "s")
$calc = 1;
if ($returntype == "m")
$calc = 60;
if ($returntype == "h")
$calc = (60*60);
if ($returntype == "d")
$calc = (60*60*24);
$_d1 = explode("-", $start_date);
$y1 = $_d1[0];
$m1 = $_d1[1];
$d1 = $_d1[2];
$_d2 = explode("-", $end_date);
$y2 = $_d2[0];
$m2 = $_d2[1];
$d2 = $_d2[2];
if (($y1 < 1970 || $y1 > 2037) || ($y2 < 1970 || $y2 > 2037))
{
return 0;
} else
{
$today_stamp = mktime(0,0,0,$m1,$d1,$y1);
$end_date_stamp = mktime(0,0,0,$m2,$d2,$y2);
$difference = round(($end_date_stamp-$today_stamp)/$calc);
return $difference;
}
}
echo date_diff("2004-06-6", "2004-06-07", "s");
?>
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43091
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43091&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43091&report=yes
Search -- http://master.php.net/manage/user-notes.php