php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66118 date_format prints incorrect GMT offset during time change hour
Submitted: 2013-11-19 15:38 UTC Modified: 2017-03-19 11:15 UTC
Votes:4
Avg. Score:3.8 ± 1.6
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: david dot sheldon at carrierweb dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.5.6 OS: Linux, windows7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david dot sheldon at carrierweb dot com
New email:
PHP Version: OS:

 

 [2013-11-19 15:38 UTC] david dot sheldon at carrierweb dot com
Description:
------------
For the hour where the clock changes, date() reports the correct offset/timezone abbreviation, and date_format() reports the incorrect offset, appearing to use the offset for an hour later.

Test script:
---------------
// http://3v4l.org/GVjMn
date_default_timezone_set("America/New_York");
$timeStamp = 1352008800;

$date= date(DateTime::ISO8601, $timeStamp);
$dateTime = new DateTime();
$dateTime->setTimestamp($timeStamp);
$dateFormat = date_format($dateTime, DateTime::ISO8601);
echo "Date: $date\nDateFormat: $dateFormat\n";

Expected result:
----------------
Both lines the same:
Date: 2012-11-04T01:00:00-0500
DateFormat: 2012-11-04T01:00:00-0500

Actual result:
--------------
Date: 2012-11-04T01:00:00-0500
DateFormat: 2012-11-04T01:00:00-0400

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-19 16:20 UTC] david dot sheldon at carrierweb dot com
It appears that this is caused by $dateTime->setTimestamp().

The following code works fine:
$dateTime = new DateTime("@$timeStamp");
$dateTime->setTimezone(new DateTimeZone("America/New_York"));
$dateFormat = $dateTime->format(DateTime::ISO8601);
 [2017-03-19 11:15 UTC] heiglandreas@php.net
-Status: Open +Status: Not a bug
 [2017-03-19 11:15 UTC] heiglandreas@php.net
Due to the way you created the datetime-object the calculations were wrong. As David Sheldon pointed out when done in the intended way everything works out correctly.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 11:01:32 2025 UTC