?
Solved

PHP/MySQL timezones screwing up

Posted on 2011-03-18
5
Medium Priority
?
458 Views
Last Modified: 2012-05-11
OK,

I have a problem. I'm setting up a sight that will end up holding large amounts of client data records. Because the clients can export and import their data, i have to be able to maintain session based timezones with in the site and server.

Right now my server is set to GMT. When i run the date command on the shell i see, which is correct at time of posting.

    Fri Mar 18 20:04:32 GMT 2011

Then when i do hwclock --show is gives me, again this is was correct.

    Fri 18 Mar 2011 08:06:22 PM GMT

Now when i tell php to change it's timezone to GMT-4 (since that is my timezone factoring in DST)

    date_default_timezone_set('Etc/GMT-4');
    echo date("m/d/Y g:i:s A T");

I get 03/19/2011 00:11:35 AM GMT-5 Is is totally wrong in stead of taking 5 hours away it added 5 hours.

So then I did this:

    date_default_timezone_set('Etc/GMT+4');
    echo date("m/d/Y g:i:s A T");

I got 03/18/2011 4:14:56 PM GMT+4. Which is the correct time. MySQL does the same thing. It seems like both are wanting to invert the time adjustments. Am i missing something on the settings?

0
Comment
Question by:Pyromanci
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:ramelong
ID: 35169815
You may try this in order to determinate if anything else is wrong:
<?
ini_set('display_errors', 1);
error_reporting(E_ALL);
echo date("m/d/Y g:i:s A T");
?>

Open in new window

since some notices and warnings of time issues related are hidden in default error reporting configuration.

Additionally, accepted time zones are listed in http://ar.php.net/manual/en/timezones.php
0
 
LVL 5

Author Comment

by:Pyromanci
ID: 35173083
There are no errors reported.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35173600
This article is kind of lengthy, but it will answer your questions about time and localization.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Please read it over and then post back with a code sample showing the issue, if you still have questions.

best regards, ~Ray
0
 
LVL 5

Author Comment

by:Pyromanci
ID: 35201335
That post didn't really give me that much information that i did not know. Nor does it cover why when i tell it -5 it adds 5 and when tell it +5 it minus's 5
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 35202162
Please see the large red warning on the man page here, and see the comments in the User-Contributed notes:
http://php.net/manual/en/timezones.others.php

A line of code that says this explicitly defies the warning, and ignores the notes.  
date_default_timezone_set('Etc/GMT+4');

Don't do that.  Instead use one of the recommended Time Zone names.

Let me try this again... and then post back with a code sample showing the issue.  Thanks. ~Ray
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question