|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33871 No daylight savings time
Submitted: 2005-07-26 17:45 UTC Modified: 2005-08-13 01:00 UTC
Avg. Score:4.2 ± 1.0
Reproduced:6 of 8 (75.0%)
Same Version:2 (33.3%)
Same OS:2 (33.3%)
From: jeremy at techtrav dot com Assigned: derick (profile)
Status: No Feedback Package: Date/time related
PHP Version: 5.1.0b3 OS: Windows XP Apache 2
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.
Block user comment
Status: Assign to:
Bug Type:
From: jeremy at techtrav dot com
New email:
PHP Version: OS:


 [2005-07-26 17:45 UTC] jeremy at techtrav dot com
the newest 5.1.X version of PHP does not seem to work with day light savings time. the Expected result was recieved from PHP 5.0.4

I am adding 6 days to Oct 25th to cross over daylight savings time on Oct 30th.  There should be 25 hours in Oct 30th.

Reproduce code:
$date = strtotime('25 Oct');
echo date('m/d/Y H:m:s', $date+(86400*6));

Expected result:
10/30/2005 23:10:00 

Actual result:
10/31/2005 00:10:00 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-26 17:49 UTC]
Obviosly "6 days" is not equal to "86400*6", exactly because of daylight savings.
Change this line:
echo date('m/d/Y H:m:s', $date+(86400*6));
echo date('m/d/Y H:m:s', strtotime("+6 days", $date));
 [2005-07-26 17:53 UTC] jeremy at techtrav dot com
Actually I realize 86400*6 should not be right as my code displays below. It should give you back one hour short, however when I do add 86400*6 onto the day in PHP 5.1.X I am getting the exact 6 days out.  That would be a problem.  Again PHP 5.0.4 handles this correctly.
 [2005-07-26 17:56 UTC]
Please run this code with 5.0.4 and tell me what you get:
$date = strtotime('25 Oct');
var_dump(date('m/d/Y H:m:s', $date+(86400*6)));
var_dump(date('m/d/Y H:m:s', strtotime("+6 days", $date)));
 [2005-07-26 18:02 UTC] jeremy at techtrav dot com
you get the expected result:

string(19) "10/30/2005 23:10:00" string(19) "10/31/2005 00:10:00" 

However in PHP 5.1.X I get:
string(19) "10/31/2005 00:10:00" string(19) "10/31/2005 00:10:00" 

Which is wrong.
 [2005-07-26 18:05 UTC]
Please try using this CVS snapshot:
For Windows:

>you get the expected result:
No, *I* get the expected result with both versions.
 [2005-07-26 18:12 UTC] jeremy at techtrav dot com
I have upgraded to the newest snap as you have requested and I am still getting the same results.  PHP 5.0.4 returns the correct time.  PHP 5.1.X returns the wrong time.  Could this be an operating system issue?  I am on Windows XP with Apache 2.
 [2005-07-26 18:16 UTC]
This could be also a timezone issue.
What's your TZ ?
 [2005-07-26 18:21 UTC] jeremy at techtrav dot com
I am Central Standard Time in MN and we are on Day light Savings time.
 [2005-08-04 10:11 UTC] xczimi at sztaki dot hu
I unpacked both 5.0.4, 5.1.0b3 and the latest code to my Win XP box, and tried the following in command line:

C:\devtool>php-5.1.0b3\php -r "echo date('r');"
Thu, 04 Aug 2005 08:05:40 +0000

C:\devtool>php-5.0.4\php -r "echo date('r');"
Thu, 04 Aug 2005 10:05:45 +0200

C:\devtool>php-latest\php -r "echo date('r');"
Thu, 04 Aug 2005 08:10:33 +0000

I think the oly problem is that php doesn't read the timezone of the Operating system.

 [2005-08-04 16:32 UTC] jeremy at techtrav dot com
well the problem comes when you cross the daylight savings time day of Oct 30th.  Strtotime will handle the 25 hour day just great.  Remebering there are 25 hours in Oct 30th is important.  That is why when you run the following code in PHP 5.0.4

echo date('r', (strtotime('oct 25')+(86400*6)));

you do get (which is right):
Sun, 30 Oct 2005 23:00:00 -0600

an hour short of Oct 31st.  However when you run that code in PHP 5.1.X you find that Oct 30th does not contain 25 hours.

Mon, 31 Oct 2005 00:00:00 +0000

This difference will definitely screw up scripts that are particularly time sensitive, like my field of Travel.
 [2005-08-04 16:43 UTC]
Look at the formatted date:
Mon, 31 Oct 2005 00:00:00 +0000

It doesn't have a timezone offset, so it seems that "xczimi" is right. Does it help if you add:
date_default_timezone_set("America/New_York") at the top of the script?
 [2005-08-04 16:44 UTC] jeremy at techtrav dot com
Oh now I understand Czimi comment.  If PHP 5.1.X is not looking at the time zone on my XP box then it is not going to know that Oct 30th is daylight savings time.  I think Czimi is probably right, PHP 5.1.X is not looking at the time zone my my XP box.
 [2005-08-04 16:51 UTC] jeremy at techtrav dot com
I tried adding that line to the top of my code.  I am not familar with that function nor do I find it in the documentation.  I get a fatal error:
Fatal error: Call to undefined function date_default_timezone_set() 

when I run this script:
echo date('r', (strtotime('oct 25')+(86400*6)));

I would agree with you in your conclusion though that it would appear that PHP 5.1.X is not reading the timezone of the local machine.
 [2005-08-04 16:53 UTC]
Now, if we can find a way how PHP can guess the correct timezone from your windows box (like it can do on most unices) that would be nice - but I think it's quite impossible.

BTW, if you use error_reporting(E_ALL) you'd have gotten a warning about this...
 [2005-08-04 16:54 UTC]
That function is only there in the snapshots, please try that instead. (and pick latest cvs (5.1-dev) there).
 [2005-08-04 16:55 UTC] jeremy at techtrav dot com
okay I figured out how to set my time zone.
I ran the following code in PHP 5.0.4 and PHP 5.1.X and recieved the same result

echo date('r', (strtotime('oct 25')+(86400*6)));

This would mean the bug is simply that PHP5.1.X is not looking at the time zone on the local machine.
 [2005-08-04 17:01 UTC] jeremy at techtrav dot com
By the way I do have E_ALL turned on, on my machine.  After all I don't run my windows box with PHP in production.  I use my windows box for development. Our PHP production runs on OpenBSD servers.

I don't quite understand this comment of yours:

"Now, if we can find a way how PHP can guess the correct timezone from your windows box "

PHP 5.0.4 reads my TZ perfectly and gives you the expected result.  Why would PHP 5.1.X not be able to?
 [2005-08-05 12:53 UTC]
Please try using this CVS snapshot:
For Windows:

Sorry, but I've tested on windows and it works perfectly. Are you sure you are using an up-to-date snapshot? And that means PHP 5.1.0 beta 3 is old...
 [2005-08-05 13:30 UTC] joerg dot klein at ifsam dot lu
it seems that I have a related problem:

I am on GMT+1
for the following example the system time is 11:00
=> 09:00

set system time-zone to GMT(+0)
=> 09:00

set system time to 10:00
=> 08:00

It seems that php don't have the correct timezone. This error occurs since 5.1.0b3.

My box runs on win2000SP4 with the latest snapshot.
 [2005-08-05 13:36 UTC]
to derick:
actually its not that difficult to guess the timezone on windows (with the comming winfx api will be even easier).

After some research on the web and some testing:

#include <time.h>
main () {
  time_t t;
  localtime ((time(&t), &t)); // fill the _tzname var
  printf("TZ=%s TZDST=%s\n", _tzname[0], _tzname[1]);

with GMT outputs:

_tzname[0] is the timezone abbr name. _tzname[1] is filled if the current timezone has DST changes.

more testing:
Pacific time:

Central time:



The problem here is that our DB doesn't have these abbreviations. But with some trialing we could all tz settings that windows uses and link them to the main db.
 [2005-08-05 13:55 UTC]
A better program would be:

#include <time.h>
#include <stdio.h>

main () {
  time_t t;
  struct tm *tstruct;

  tstruct = localtime ((time(&t), &t));
  printf("TZ=%s TZDST=%s is_dst:%d\n", _tzname[0], _tzname[1], tstruct->tm_isdst);


is_dst is 0 if DST isn't in effect, or positive otherwise.
Although you cannot get the precise tz info, you can get the timezone offset with ease.
there is a nice example here: but I can't test it, because cygwin's win32 api doesn't export some required structures (and I didn't installed MSVC yet).
 [2005-08-05 14:24 UTC]
This is datas from your system (or the version you use). The problem with windows is that there is many different datas in each single product version.

 [2005-08-13 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 12:03:36 2021 UTC