php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37093 Daylight Savings Time error
Submitted: 2006-04-15 23:28 UTC Modified: 2006-04-16 19:22 UTC
From: robertsaenz at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.1.2 OS: Windows XP Professional
Private report: No CVE-ID: None
 [2006-04-15 23:28 UTC] robertsaenz at gmail dot com
Description:
------------
The time returned from the date() function is incorrect.  The time is an hour behind what it actually should be.  This occured after the clocks were set forward an hour.  The timezone is: MST and I am in DST territory.  The code should explain my problem better.  My server is set to use DST and now since our clocks have been set forward (as mentioned before) I've been getting that hour time difference.  My work around for now is to set the server's clock an hour ahead which outputs the expected result, however this is not what I want to do.  Is there maybe a work around for this.  I searched the bugs but didn't find anything that lead to the exact problem I had, but if there is a duplicate I apologize and if you can point me to it that would be great. Thanks.

Reproduce code:
---------------
<?php
  echo date("Y-m-d H:i:s T I");
?>


Expected result:
----------------
2006-04-15 17:19:55 MST 0

Actual result:
--------------
2006-04-15 16:19:55 MST 0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-16 08:06 UTC] tony2001@php.net
>The timezone is: MST and I am in DST territory. 
Which means it's actually MDT, not MST.

What if you set the correct timezone with date_default_timezone_set() ?
 [2006-04-16 08:36 UTC] robertsaenz at gmail dot com
Oops! Sorry meant to say MDT and I should have expected MDT but I didn't put that down, nor did I put a 1 expected for DST in expected result.  Yeah using date_default_timezone_set() worked. Is there a way to change this permanently or do I have to do this for every script that uses the date function?  Thanks.
 [2006-04-16 08:41 UTC] tony2001@php.net
Well, I guess using date.timezone INI setting is even easier. But yes, you can use date_default_timezone_set()/_get() either.
 [2006-04-16 09:28 UTC] robertsaenz at gmail dot com
I must not be doing something right.  I'm trying to do the date.timezone method but for some reason it is not working for me. I'm doing:
date.timezone = "US/Mountain"

Is there a specific area that it needs to go under php.ini? Or can it just go anywhere in the ini file?  I tried it without quotes to no avail.  Any help would be great thanks.  I'm really trying to avoid having to use the date_default_timezone_set() function.
 [2006-04-16 09:39 UTC] tony2001@php.net
What do you mean by "not working"?
Did you restart apache? Did you look in phpinfo() and check that you're modifying the right php.ini file?
 [2006-04-16 09:50 UTC] derick@php.net
You shouldn't use US/Mountain anyway, use one of the America/* listed here: http://www.php.net/manual/en/timezones.america.php

 [2006-04-16 19:22 UTC] robertsaenz at gmail dot com
What I meant by "not working" was that I am still getting:

2006-04-16 12:19:55 MST 0

When I'm expecting:

2006-04-16 13:19:55 MDT 1

I restarted Apache (which is Apache2 by the way... don't know if it matters but I thought I would throw that in there as extra info).  I also stopped it and the started it manually.  I even restarted the server and I still get the same result.

I'm using the correct php.ini (I just double checked to make sure).

The reason I used "US/Mountain" was because it worked with the date_default_timezone_set().  However, I tried "America/Denver" (who is in the same timezone).  I got the same result.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 19:01:30 2024 UTC