Bug #62927 [Fbk->Nab]: date function peculiar return for 11/04/2012
| From: | rasmus@php.net | Date: | Tue, 28 Aug 2012 02:03:48 +0000 |
| Subject: | Bug #62927 [Fbk->Nab]: date function peculiar return for 11/04/2012 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-172966@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62927&edit=1
ID: 62927
Updated by: rasmus@php.net
Reported by: dan at chirica dot net
Summary: date function peculiar return for 11/04/2012
-Status: Feedback
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Ubuntu 10.4
PHP Version: 5.3.2
Block user comment: N
Private report: N
New Comment:
You have discovered Daylight Savings Time. DST changes the first Sunday in
November which is Nov.4. Your output looks very wrong because you are using 'h'
instead of 'H' so you are printing 12-hour hours instead of 24. Make it an 'H'
instead and you will see they are 23 hours apart. Adding 24*3600 over a DST
change is going to change the time by either 23 or 25 hours, never 24. This is
why we have DateTime::add()
Previous Comments:
------------------------------------------------------------------------
[2012-08-28 01:56:03] aharvey@php.net
What time zone do you have set?
------------------------------------------------------------------------
[2012-08-27 20:58:29] dan at chirica dot net
$ php -v
PHP 5.3.2-1ubuntu4.17 with Suhosin-Patch (cli) (built: Jun 19 2012 03:21:35)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH
$ cat date.php
<?php
$date1 = 1352012400;
//$date2 = $date1 + 86400 which should be next day
$date2 = 1352098801;
echo "date1: " . date ("Y-m-d_h:i:s", $date1) . "\n";
echo "date2: " . date ("Y-m-d_h:i:s", $date2) . "\n";
//Output
//date1: 2012-11-04_12:00:00
//date2: 2012-11-04_11:00:01
?>
$php date.php
date1: 2012-11-04_12:00:00
date2: 2012-11-04_11:00:01
Similar behavior on Mac OS 10.8 with PHP PHP (MAMP) 5.3.2 (cli) (built: Mar 5
2010 16:45:34)
------------------------------------------------------------------------
[2012-08-26 18:19:03] andreas at heigl dot org
I can NOT reproduce the issue on MacOS X 10.7
Here is the output of my console
$ php -v
PHP 5.3.16 (cli) (built: Aug 17 2012 11:13:15)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
$ cat /tmp/datetest.php
<?php
$date1 = 1352012400;
//$date2 = $date1 + 86400 which should be next day
$date2 = 1352098801;
echo "date1: " . date ("Y-m-d_h:i:s", $date1) . "\n";
echo "date2: " . date ("Y-m-d_h:i:s", $date2) . "\n";
$ php -f /tmp/datetest.php
date1: 2012-11-04_08:00:00
date2: 2012-11-05_08:00:01
------------------------------------------------------------------------
[2012-08-24 18:33:29] dan at chirica dot net
Description:
------------
---
From manual page: http://www.php.net/function.date#refsect1-function.date-
returnvalues
---
Test script:
---------------
$date1 = 1352012400;
//$date2 = $date1 + 86400 which should be next day
$date2 = 1352098801;
echo "date1: " . date ("Y-m-d_h:i:s", $date1) . "\n";
echo "date2: " . date ("Y-m-d_h:i:s", $date2) . "\n";
//Output
//date1: 2012-11-04_12:00:00
//date2: 2012-11-04_11:00:01
Expected result:
----------------
date1: 2012-11-04_12:00:00
date2: 2012-11-05_12:00:00
Actual result:
--------------
//Output
//date1: 2012-11-04_12:00:00
//date2: 2012-11-04_11:00:01
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62927&edit=1