Mysql converting TIMESTAMP to INTEGER - timezones Mysql converting TIMESTAMP to INTEGER - timezones mysql mysql

Mysql converting TIMESTAMP to INTEGER - timezones


You don't need to store the time in INT's. MySQL's TIMESTAMP type does that anyway (it uses standard Unix timestamps to store the time) and they are always in UTC timezone.

You only need to set the session timezone and all TIMESTAMP columns will be converted from/to your zone when you update/select them.

You can set the zone at connect/initialization time once:

SET time_zone = '+10:00';

And then you can select/update the time in your zone directly

SELECT timestamp_column FROM table ...

I'm not very familiar with datetime libs but I guess they use the timezone you provided and the time in question to determine timezone and daylight savings offsets.

In the example you provided I think one of the values is actually invalid, because the clock is supposed to jump from 01:59:59 to 03:00:00 and 02:00:00 never actually happened. The UNIX_TIMESTAMP function probably returns the nearest second in that case.