php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62927 date function peculiar return for 11/04/2012
Submitted: 2012-08-24 18:33 UTC Modified: 2012-08-28 02:03 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: dan at chirica dot net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.2 OS: Ubuntu 10.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dan at chirica dot net
New email:
PHP Version: OS:

 

 [2012-08-24 18:33 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-26 18:19 UTC] 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-27 20:58 UTC] 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-27 20:58 UTC] dan at chirica dot net
-Operating System: Linux (Ubuntu 10.4) Mac OS 10.7 +Operating System: Ubuntu 10.4 -PHP Version: 5.3.16 +PHP Version: 5.3.2
 [2012-08-28 01:56 UTC] aharvey@php.net
-Status: Open +Status: Feedback
 [2012-08-28 01:56 UTC] aharvey@php.net
What time zone do you have set?
 [2012-08-28 02:03 UTC] rasmus@php.net
-Status: Feedback +Status: Not a bug
 [2012-08-28 02:03 UTC] rasmus@php.net
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()
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 10:01:30 2024 UTC