Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 828819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:47:06+00:00 2026-05-15T03:47:06+00:00

Does anyone know if there is a function to obtain the server’s time zone

  • 0

Does anyone know if there is a function to obtain the server’s time zone setting in MySQL?

UPDATE

This doesn’t output any valid info:

mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM             | SYSTEM              |
+--------------------+---------------------+

If MySQL can’t know the exact time_zone being used, that’s fine – we can also involve PHP as long as I can get valid info (not like SYSTEM)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:47:07+00:00Added an answer on May 15, 2026 at 3:47 am

    From the manual (section 9.6):

    The current values of the global and client-specific time zones can be retrieved like this:

    mysql> SELECT @@global.time_zone, @@session.time_zone;

    Edit The above returns SYSTEM if MySQL is set to use the system’s timezone, which is less than helpful. Since you’re using PHP, if the answer from MySQL is SYSTEM, you can then ask the system what timezone it’s using via date_default_timezone_get. (Of course, as VolkerK pointed out, PHP may be running on a different server, but as assumptions go, assuming the web server and the DB server it’s talking to are set to [if not actually in] the same timezone isn’t a huge leap.) But beware that (as with MySQL), you can set the timezone that PHP uses (date_default_timezone_set), which means it may report a different value than the OS is using. If you’re in control of the PHP code, you should know whether you’re doing that and be okay.

    But the whole question of what timezone the MySQL server is using may be a tangent, because asking the server what timezone it’s in tells you absolutely nothing about the data in the database. Read on for details:

    Further discussion:

    If you’re in control of the server, of course you can ensure that the timezone is a known quantity. If you’re not in control of the server, you can set the timezone used by your connection like this:

    set time_zone = '+00:00';
    

    That sets the timezone to GMT, so that any further operations (like now()) will use GMT.

    Note, though, that time and date values are not stored with timezone information in MySQL:

    mysql> create table foo (tstamp datetime) Engine=MyISAM;
    Query OK, 0 rows affected (0.06 sec)
    
    mysql> insert into foo (tstamp) values (now());
    Query OK, 1 row affected (0.00 sec)
    
    mysql> set time_zone = '+01:00';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select tstamp from foo;
    +---------------------+
    | tstamp              |
    +---------------------+
    | 2010-05-29 08:31:59 |
    +---------------------+
    1 row in set (0.00 sec)
    
    mysql> set time_zone = '+02:00';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select tstamp from foo;
    +---------------------+
    | tstamp              |
    +---------------------+
    | 2010-05-29 08:31:59 |      <== Note, no change!
    +---------------------+
    1 row in set (0.00 sec)
    
    mysql> select now();
    +---------------------+
    | now()               |
    +---------------------+
    | 2010-05-29 10:32:32 |
    +---------------------+
    1 row in set (0.00 sec)
    
    mysql> set time_zone = '+00:00';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select now();
    +---------------------+
    | now()               |
    +---------------------+
    | 2010-05-29 08:32:38 |      <== Note, it changed!
    +---------------------+
    1 row in set (0.00 sec)
    

    So knowing the timezone of the server is only important in terms of functions that get the time right now, such as now(), unix_timestamp(), etc.; it doesn’t tell you anything about what timezone the dates in the database data are using. You might choose to assume they were written using the server’s timezone, but that assumption may well be flawed. To know the timezone of any dates or times stored in the data, you have to ensure that they’re stored with timezone information or (as I do) ensure they’re always in GMT.

    Why is assuming the data was written using the server’s timezone flawed? Well, for one thing, the data may have been written using a connection that set a different timezone. The database may have been moved from one server to another, where the servers were in different timezones (I ran into that when I inherited a database that had moved from Texas to California). But even if the data is written on the server, with its current time zone, it’s still ambiguous. Last year, in the United States, Daylight Savings Time was turned off at 2:00 a.m. on November 1st. Suppose my server is in California using the Pacific timezone and I have the value 2009-11-01 01:30:00 in the database. When was it? Was that 1:30 a.m. November 1st PDT, or 1:30 a.m. November 1st PST (an hour later)? You have absolutely no way of knowing. Moral: Always store dates/times in GMT (which doesn’t do DST) and convert to the desired timezone as/when necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 418k
  • Answers 418k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can map start date to financial year using YEAR(DATEADD(M,-3,JoinDate)… May 15, 2026 at 9:51 am
  • Editorial Team
    Editorial Team added an answer It's calling a base class constructor, passing the argument splashForm… May 15, 2026 at 9:51 am
  • Editorial Team
    Editorial Team added an answer What you need to remember is that dynamic resolution basically… May 15, 2026 at 9:51 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.