Michel Michel - 1 month ago 24
MySQL Question

MySql - SELECT TimeStamp Column in UTC format

In my Mysql 5.0 DB I have a column to control LastUpdated information. The Column is a TimeStamp one and MySql automatic updates data.

I'm trying to select this column in UTC format.

The problem is that the server is setup to US datetime. According to MySql documentation, the DB stores the information in UTC but when I want to display information, it converts it to Server's time.

Is there any way to do SELECT command avoiding this convertion?

Answer

Besides changing the default timezone of the server, the timezone can also be adjusted per connection by executing this SQL statement:

SET time_zone = timezone;

Where timezone is the name of the timezone (see MySQL docs).

Alternatively, you can also convert a timestamp to a different timezone using the CONVERT_TZ function.