Skip to content

Instantly share code, notes, and snippets.

@andrewmmc
Last active January 31, 2018 02:14
Show Gist options
  • Save andrewmmc/4de77b250d653edddf029564b84af049 to your computer and use it in GitHub Desktop.
Save andrewmmc/4de77b250d653edddf029564b84af049 to your computer and use it in GitHub Desktop.
[MySQL] Server Time Zone Support

MySQL - Server Time Zone Support

## The current values of the global and client-specific time zones can be retrieved like this:
SELECT @@global.time_zone, @@session.time_zone;

## NOW() returns current datetime based on system timezone in ‘YYYY-MM-DD HH:MM:SS’
## UNIX_TIMESTAMP() returns a Unix timestamp in seconds since '1970-01-01 00:00:00' UTC if no arguments are passed
## UTC_TIMESTAMP() returns current UTC datetime in 'YYYY-MM-DD HH:MM:SS'
SELECT NOW(), UNIX_TIMESTAMP(), UTC_TIMESTAMP();

## Set the client-specific session timezone:
SET @@session.time_zone = 'Asia/Hong_Kong';

## Reset the client-specific session timezone:
SET @@session.time_zone = SYSTEM;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment