1

I want to know what is the time zone that is currently set in the MySQL server. I do not have administrator rights to the computer I am using so I've tried the method by checking the registry.

I am doing a table with a timestamp column and I noticed the time stamped is different than the one on my computer's time. Is there any reason for this? How do I check what timezone it is on the MySQL server? How do I change it to match my local/computer's time?

Anthony
  • 36,459
  • 25
  • 97
  • 163
kross
  • 475
  • 1
  • 11
  • 31
  • Does this answer your question? [How do I get the current time zone of MySQL?](https://stackoverflow.com/questions/2934258/how-do-i-get-the-current-time-zone-of-mysql) – Ryan Mar 11 '20 at 16:25

6 Answers6

1

You can set the timezone (if you know your offset) for the session by using

    set session time_zone = '+00:00';

and to revert to the system default

    set session time_zone 'SYSTEM';
Cohan
  • 4,384
  • 2
  • 22
  • 40
1
  1. In an SQL timestamp column, SQL automatically converts the time to UTC before storing it, using the session's current time offset. It will be the machine's time offset unless you change it (3). Depending on your server's settings (sql.ini), it may or may not always concert back to the expect timezone. This probably explains the time discrepancy.

  2. To get the current timezone offset, try executing

    SELECT @@session.time_zone;
    
  3. To manually override the SQL timezone for the rest of a particular session, execute the following, replacing 00:00 with your desired offset:

    SET @@session.time_zone = "+00:00";
    
Community
  • 1
  • 1
BradzTech
  • 2,755
  • 1
  • 16
  • 21
  • *"using the machine's current time offset"* -- technically, it's the current *session's* time zone offset, which is the same as the system if it hasn't been changed. It will never change back to the "original" time zone as such, unless the session time zone at the time of retrieval happens to be the same as it was when the value was stored. – Michael - sqlbot Jun 10 '15 at 11:32
0

Have a look at the system_time_zone system variable.

Donal
  • 31,121
  • 10
  • 63
  • 72
0

This may help:

http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html

You can set the system time zone for MySQL Server at startup with the --timezone=timezone_name option to mysqld_safe. You can also set it by setting the TZ environment variable before you start mysqld. The permissible values for --timezone or TZ are system dependent. Consult your operating system documentation to see what values are acceptable.

0

You can convert a given timestamp to UTC (or any other TZ you want) with CONVERT_TZ

SELECT CONVERT_TZ(NOW(),@@session.time_zone,'GMT');

Note that I use NOW() as simple demonstration, you would put in the timestamp you wanted to convert.

By the same token, you could convert a timestamp in your local TZ to the system

SELECT CONVERT_TZ($timestamp,'Your Time Zone' @@session.time_zone);
Anthony
  • 36,459
  • 25
  • 97
  • 163
0

To check your shared server

<?php
  echo date_default_timezone_get();
?>

To change

<?php
    date_default_timezone_set("Africa/Addis_Ababa");
    echo date_default_timezone_get();
?>
  • Important to note that this will only change the timezone *for the current PHP script*. Right after it's done executing, this change will be forgotten. Also, this will not change the timezone that MySQL is using in any way, which is what the original question was about. – Garcia Hurtado Mar 09 '21 at 17:32