+ Reply to Thread
Results 1 to 3 of 3

Thread: MySQL timezone, NOW() command problems

  1. #1
    raydarken is offline x10Hosting Member raydarken is an unknown quantity at this point
    Join Date
    Feb 2010
    Posts
    2

    MySQL timezone, NOW() command problems

    Hello, I am trying to use the mysql command NOW() in order to retrieve the latest records from the last 10 minutes in my database. The problem I am having is that the NOW() function returns a timezone that is different than the one being reported as being used on the server, making the function useless for me unless I convert my timestamps from UTC to some other timezone. Can anyone please help me understand why the timezones on this MySQL server seem so strange? Thank you in advance.

    I am on the cossacks server.

    Using the sql command "show variables like "%time_zone%";" returns:
    system_time_zone CST
    time_zone SYSTEM

    At
    2010-02-09 07:00:00 GMT: (2010-02-09 01:00:00 CST):

    The NOW() time reads:
    2010-02-10 03:00:00 (+8 Hours! A different day! unknown timezone, should be CST?)

    The UTC_TIMESTAMP() time reads:
    2010-02-10 09:00:00 (+14 Hours! A different day! UTC should be 07:00:00)
    Last edited by raydarken; 02-09-2010 at 02:29 PM.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: MySQL timezone, NOW() command problems

    Note that the value returned by NOW() is 6 hours behind UTC_TIMESTAMP(), so those at least are consistent. Try PHP's time functions; on Lotus, they report a timezone of EST and the correct time for that timezone. MySQL is 14 hours, 16 seconds fast relative to the PHP functions. I'm not certain what's going on with the MySQL server.

    To have NOW work with UTC rather than the server timezone, you can set the timezone on a per-connection basis:
    Code:
    SET time_zone = '+0:00';
    Read over § 9.7 of the MySQL manual, "MySQL Server Time Zone Support", for more information.
    Last edited by misson; 02-09-2010 at 08:00 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    raydarken is offline x10Hosting Member raydarken is an unknown quantity at this point
    Join Date
    Feb 2010
    Posts
    2

    Re: MySQL timezone, NOW() command problems

    mission, thank you for the reply. I appreciate it!

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  3. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  4. MySQL change timezone
    By jaybe in forum Free Hosting
    Replies: 0
    Last Post: 07-11-2008, 08:47 AM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers