Closed Thread
Results 1 to 9 of 9

Thread: timezones

  1. #1
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    timezones

    I am having a few problems, I have tried dev.mysql.com and php.net trying to find a solution but came up short.

    here goes:

    I need to convert my the Datetime of user post to a specific timezone (dosent really matter which as long as i know which one it is) I tried to get my server timezone by running :

    Code:
    SELECT @ @global.time_zone
    at the MySQL prompt on my server But it returns a value of SYSTEM

    Also is there a php function that would easily allow for me to convert from one time zone to another just for displaying data?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: timezones

    I think you could store the time zone difference in a var, then do
    Code:
    $display strtotime($zone." hours"); 
    that is depending on having your computer set to UTC. If you don't, you could try read out your timezone in hours with
    Code:
    date("O")/100 
    and add that to $zone used above to get the correct difference.
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  4. #3
    Jordan Guest

    Re: timezones

    Run this query (if you are root):

    Code:
    SET GLOBAL time_zone = timezone;
    Replace timezone with the value you want. If you are not root, you can set the timezone per session:

    Code:
    SET time_zone = timezone;
    Here is where this information comes from: MySQL :: MySQL 5.1 Reference Manual :: 9.7 MySQL Server Time Zone Support

    To convert from one timezone to the next use convert_tz:

    Code:
    SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
    From: MySQL :: MySQL 5.1 Reference Manual :: 11.6 Date and Time Functions

  5. #4
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    Re: timezones

    Thanks guys that was really helpful.

    One thing I don't understand thou is this:

    Quote Originally Posted by Jordan View Post

    If you are not root, you can set the timezone per session:

    Code:
    SET time_zone = timezone;
    Here is where this information comes from: MySQL :: MySQL 5.1 Reference Manual :: 9.7 MySQL Server Time Zone Support

    I read the info at the link but it did not make sence to me. I also checked in my mySQL pocket guide and found nothing. Could some one show me an example of how to use this/a MySQL session veriable?

  6. #5
    Jordan Guest

    Re: timezones

    That is an SQL query so you just need to run it before executing any other queries.

  7. #6
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: timezones

    I believe that you would only need to use CONVERT_TZ really, and use the default timezone set on the server as it is.
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  8. #7
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    Re: timezones

    Quote Originally Posted by orjan View Post
    I believe that you would only need to use CONVERT_TZ really, and use the default timezone set on the server as it is.
    That was one of the problems i was having.

    Quote Originally Posted by zeroradius
    I tried to get my server timezone by running :

    Code:
    SELECT @ @global.time_zone
    at the MySQL prompt on my server But it returns a value of SYSTEM
    I understand how to do it now. Thank you both that saved me a considerable headache.

  9. #8
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: timezones

    How do you do it?
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  10. #9
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    Re: timezones

    you run

    Code:
    SET time_zone = timezone;
    at the mysql prompt. One thing I just thought of thou, if my hosting resets my server and dosent tell me, it will screw up my timezones from there on out (-_-) that poses a potential problem. Sence session veriable are dynamic could I execute this when users log in as an extra precation by running it the way i would anyother mysql querry?

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Timezones
    By wim DC in forum The Lounge
    Replies: 7
    Last Post: 05-25-2010, 12:02 PM
  2. Time & Timezones
    By Bioshox in forum PHP Tutorials
    Replies: 0
    Last Post: 03-01-2010, 11:22 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts