|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13900 date(I) does not correctly identify daylight saving time
Submitted: 2001-11-01 09:52 UTC Modified: 2001-11-06 00:20 UTC
From: bmplummer1 at home dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.0.6 OS: Windows NT/XP
Private report: No CVE-ID: None
 [2001-11-01 09:52 UTC] bmplummer1 at home dot com
Bug id #13880
Status: Bogus  User Modify   Dev Modify 
Reported: 2001-10-30 19:25:30 
Type: Date/time related 
OS: Windows NT/XP 
PHP Version: 4.0.6 
Summary: date(I) does not correctly identify daylight saving time 

[2001-10-30 19:25:30]

There appears to be a bug in the date() function when using the I (capital i) format. 
Date(I) always returns 0 (zero) no matter what the date is.  Date(I) is used to determin
if a date occurs during daylight saving time or not.  Here is the script I am using:

if (date(I, mktime(0,0,0,6,1,2001))=1) {
    do this;
} else {
    do that;

No mater what the date is it always returns zero.  I have tried setting date(I) to a
variable outside of the if/then statement but it always sets the variable to zero.  I have
tried setting the timestamp to a variable first and using it in date():

$ts = mktime(0,0,0,6,1,2001);
$ds = date(I, $ts);

That doesn't work either, returns zero. No matter what I do it just doesn't work.  Does
this part of date() even work?

Running PHP 4.05 with Zend Optimizer v1.1.0 on Windows NT 4.0 build 1381, CGI version,
Apache/1.3.20 .  Also doesn't work on PHP 4.06 on Windows XP, CGI version,

Thank you for your consideration and hard work.  PHP is a great product.  Keep up the good

Bradford Plummer
[2001-10-30 19:33:48]

Two obvious problems with your test script.

I should be in quotes, and = should be ==.  Make those changes and try again.

This works okay on Linux.

[2001-10-30 19:36:28]

Works on Windows XP as well with 4.0.6.

[2001-10-30 19:36:33]

Works on Windows XP as well with 4.0.6.

[2001-11-01 01:34:05]

cnewbill said this:

Two obvious problems with your test script.
I should be in quotes, and = should be ==.  Make those changes and try again.
This works okay on Linux.


First of all...
You are right.  I left the quotes out of my bug report.  I was, however, using them in the
actual script.  If you tested my script you may have also noticed that the following
commands return a zero on a Win32 system when they should return a one:

echo date("I", mktime(0,0,0,5,1,2001));
echo date("I", mktime(0,0,0,6,1,2001));
echo date("I", mktime(0,0,0,7,1,2001));
echo date("I", mktime(0,0,0,8,1,2001));
echo date("I", mktime(0,0,0,9,1,2001));
echo date("I", mktime(0,0,0,10,1,2001));

  Also returning a zero instead of a one are:

echo date("I", mktime(0,0,0,date("m")-1,date("d"), 
echo date("I", mktime(0,0,0,date("m")-2,date("d"), 
echo date("I", mktime(0,0,0,date("m")-3,date("d"), 
echo date("I", mktime(0,0,0,date("m")-4,date("d"), 
echo date("I", mktime(0,0,0,date("m")-5,date("d"), 
echo date("I", mktime(0,0,0,date("m")-6,date("d"), 
echo date("I", mktime(0,0,0,date("m")-7,date("d"), 

    So it doesn't seem to matter how I format the original if/then statement because it
will always evaluate incorrectly because date() is doing something screwy on Win32.  Also,
I found something else while working on this.  When using the M format, date() has a
problem figuring out what month name it is supposed to return.  Here is some example

echo date("M, I", mktime(0,0,0,date("m")-1,date("d"), 
echo "<br>";
echo date("M, I", mktime(0,0,0,date("m")-2,date("d"), 
echo "<br>";
echo date("M, I", mktime(0,0,0,date("m")-3,date("d"), 
echo "<br>";
echo date("M, I", mktime(0,0,0,date("m")-4,date("d"), 
echo "<br>";
echo date("M, I", mktime(0,0,0,date("m")-5,date("d"), 
echo "<br>";
echo date("M, I", mktime(0,0,0,date("m")-6,date("d"), 
echo "<br>";
echo date("M, I", mktime(0,0,0,date("m")-7,date("d"), 

      That script returns this on my Win32 system:

Oct, 0
Aug, 0
Jul, 0
Jul, 0
May, 0
May, 0
Mar, 0

      At least it did for my yesterday (31 Oct 2001).  Notice how Jul and May are doubled?
 What happened to Apr and Jun?

Could you check in to these issues and let me know what you find out.  By the way, thank
you for responding so quickly.
Bradford Plummer


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-01 14:13 UTC]
See for why the months are doubled.

Here is my result from first script

C:\php>php t.php
X-Powered-By: PHP/4.0.6
Content-type: text/html


All 1's not 0's.

Second script 1111110

I have NO clue what it is doing on your box, mine is Windows XP RC2 I don't have access to any other windows version right now only Linux.  Can someone else verify this on NT4?  I am using the exact same PHP on XP as you.

 [2001-11-01 15:32 UTC] bmplummer1 at home dot com
Well, I am getting zeros...  I get in on PHP 4.06 on Windows XP pro and I get zeros on PHP 4.05 on Windows NT 4.0.  both are running on Apache.  Maybe that is the issue.  Are you running PHP on Apache?
 [2001-11-01 15:44 UTC]
You said you were running it as a CGI therefore my test should be equivalent without me having to use Apache.

I don't see how the CGI being called through Apache could do this.  BUT jic, please try executing your PHP CGI from the command line against those test scripts and see if you get the same results.

 [2001-11-02 21:56 UTC] bmplummer1 at home dot com
Tried it from the command line and got all zeros.
 [2001-11-03 01:09 UTC] bmplummer1 at home dot com
I downloaded 4.06 again and installed it manually.  I have a feeling that my php.ini is somehow different than the standard because when I tried to use the optimized php.ini file I couldn't even load my script.  But when I used the dist version the script worked (except for the date(I) part).  I must have my PHP configured incorrectly.  But why would it do it on two different computers and two different versions of PHP???
 [2001-11-04 19:55 UTC]
On my w2k 4.0.4pl1, it returns 1, which is wrong now, since Daylight saving time ended a week ago in Europe. Same for debian-linux. Both are correctly configured.

What's your output with this script:

var_dump(date("I", mktime(0,0,0,5,1,2001)));

On my system, it returns string(1) "1"


 [2001-11-04 22:56 UTC] bmplummer1 at home dot com
I have two comments about the last entry.

Jeroen, if you ran the same script that you put in your notes then it should have returned a 1 (one) because the date is May 1 2001 which occurs during daylight saving time.

On my Win XP pro version 2002, PHP 4.06 CGI version here is what I get:


var_dump(date("I", mktime(0,0,0,5,1,2001)));


string(1) "0"

I haven't made any special changes to my PHP.ini.  Do I need to load a special module to get this to work?  I have been able to reproduce this on two different systems.  On XP and NT 4.0 I used the PHP installer to automatically install PHP.  I also reinstalled PHP 4.06 manually on the XP system but I only used the php.ini-dist config file.

In the mean time...  Anybody know of a daylight saving time detection script before I start writing this by hand?
 [2001-11-05 03:15 UTC]
perhaps a simple reality check: what timezone does date("T") report? php could be running in a context with the timezone set to something that doesn't have a daylight savings time.

(and there is no module or php.ini setting that has anything do with what date("I") reports. if the timezone is correct, and it is wrong, then your c library is broken.)
 [2001-11-05 23:03 UTC] bmplummer1 at home dot com
Ok.  I think you nailed it.  I am in Arizona.  We don't use daylight saving time.  When I run date("T") it returns nothing.  Blank.  Is date("I") dependant on your timezone?  If so then it won't work for servers running PHP in Arizona.  Uh...  Is there an alternative or will I just have to write this by hand?
 [2001-11-06 00:20 UTC]
if you want to check if a date occurs during daylight savings time, you have to set your timezone to one that observes daylight savings time. (ie. putenv("TZ=PST8PDT"))

there's no bug here.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Nov 27 18:01:25 2020 UTC