note 116949 added to function.mktime
| From: | mh240873atwebdotde | Date: | Thu, 26 Mar 2015 00:18:34 +0000 |
| Subject: | note 116949 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202036@lists.php.net to get a copy of this message | ||
Pay attention that not all days have the same number of seconds (86400s) if you are using
date_default_timezone_set(..) and the used timezone has Daylight Saving Time (DST) e.g.
"Europe/Berlin". Under PHP 5.5.16 I get the following results:
$shortday = mktime(23,59,59, '3','29','2015') - mktime(0,0,0,
'3','29','2015) + 1; // result: 82800s (86400s - 3600s)
$normalDay = mktime(23,59,59, '1', '2','2015') - mktime(0,0,0,
'1', '1','2015) + 1; // result: 86400s
$longDay = mktime(23,59,59,'10','25','2015') -
mktime(0,0,0,'10','25','2015) + 1; // result: 90000s (86400s + 3600s)
Pitfall is noticeable if you are running an iterative loop with a code like:
echo date( 'd.m.Y', $day );
$day = $day + 86400; // 86400 = 24*3600 - frequently used in PHP code
which results in wrong date if $day reaches 2015-10-25 (end of summer time in Germany):
24.10.2015
25.10.2015
25.10.2015 // Ups! Same date twice in calendar
27.10.2015
You may workaround this by using date_default_timezone_set('UTC') where all days have the
same number of seconds.
----
Server IP: 72.52.91.14
Probable Submitter: 87.174.149.64
----
Manual Page -- http://php.net/manual/en/function.mktime.php
Edit -- https://master.php.net/note/edit/116949
Del: integrated -- https://master.php.net/note/delete/116949/integrated
Del: useless -- https://master.php.net/note/delete/116949/useless
Del: bad code -- https://master.php.net/note/delete/116949/bad+code
Del: spam -- https://master.php.net/note/delete/116949/spam
Del: non-english -- https://master.php.net/note/delete/116949/non-english
Del: in docs -- https://master.php.net/note/delete/116949/in+docs
Del: other reasons-- https://master.php.net/note/delete/116949
Reject -- https://master.php.net/note/reject/116949
Search -- https://master.php.net/manage/user-notes.php