note 111371 added to function.mktime
| From: | pascal dot bonderff at gmail dot com | Date: | Tue, 12 Feb 2013 22:37:34 +0000 |
| Subject: | note 111371 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193620@lists.php.net to get a copy of this message | ||
To calculate the number of days between two dates, do not take the integer part of the difference is
due to the transition to daylight saving time. We must take rounding:
<?php
function dateDiff($start, $end) {
$start_ts = strtotime($start);
$end_ts = strtotime($end);
$diff = $end_ts - $start_ts;
return round($diff / 86400);
}
?>
If you use the floor() instead of round() function, the result will be one day less if the start
date is before the summer time date and the end date between the summer time date and the winter
time date. This is due to the fact that the summer time date is one hour less.
----
Server IP: 69.147.83.199
Probable Submitter: 88.163.122.30
----
Manual Page -- http://php.net/manual/en/function.mktime.php
Edit -- https://master.php.net/note/edit/111371
Del: integrated -- https://master.php.net/note/delete/111371/integrated
Del: useless -- https://master.php.net/note/delete/111371/useless
Del: bad code -- https://master.php.net/note/delete/111371/bad+code
Del: spam -- https://master.php.net/note/delete/111371/spam
Del: non-english -- https://master.php.net/note/delete/111371/non-english
Del: in docs -- https://master.php.net/note/delete/111371/in+docs
Del: other reasons-- https://master.php.net/note/delete/111371
Reject -- https://master.php.net/note/reject/111371
Search -- https://master.php.net/manage/user-notes.php