note 81275 added to function.mktime
| From: | JSantillnelquenovotoporfoxathotmail at osu1 dot php dot net | Date: | Wed, 20 Feb 2008 21:21:47 +0000 |
| Subject: | note 81275 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136327@lists.php.net to get a copy of this message | ||
<?php
//Beware of this when comparing dates:
function daysBetween($date1, $date2)
{
$d1 = explode("-", $date1);
$d2 = explode("-", $date2);
$year1 = $d1[0];
$month1 = $d1[1];
$day1 = $d1[2];
$year2 = $d2[0];
$month2 = $d2[1];
$day2 = $d2[2];
$deadline1 = mktime(0, 0, 0, $month1, $day1, $year1, 0);
$deadline2 = mktime(0, 0, 0, $month2, $day2, $year2, 0);
/* If you dont put 0 at last parameter both mktime calls, and
a Daylight Saving Time is not specified,
a float days number can be returned. Is better to pass 0
in both mktimes and round the result: */
$res = round( ($deadline2 - $deadline1) / (60 * 60 * 24) );
return $res;
}
/* My Test dates: */
echo daysBetween('2008-3-5','2008-3-11');
?>
----
Server IP: 69.147.83.197
Probable Submitter: 201.141.190.69
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- https://master.php.net/note/edit/81275
Del: integrated -- https://master.php.net/note/delete/81275/integrated
Del: useless -- https://master.php.net/note/delete/81275/useless
Del: bad code -- https://master.php.net/note/delete/81275/bad+code
Del: spam -- https://master.php.net/note/delete/81275/spam
Del: non-english -- https://master.php.net/note/delete/81275/non-english
Del: in docs -- https://master.php.net/note/delete/81275/in+docs
Del: other reasons-- https://master.php.net/note/delete/81275
Reject -- https://master.php.net/note/reject/81275
Search -- https://master.php.net/manage/user-notes.php