VERSION|0.4.7.1|SUBJECT|Storing UTC dates in a MySQL DATETIME column|CONTENT|After some reading and testing, I am convinced that the DATETIME column has no notion of timezone (which is fine with me).  So I can store any date I want in a DATETIME, but I must keep track of the timezone somewhere else (or even better, just store all dates in UTC).

The problem is that MySQL fails to provide functions for converting a DATETIME to/from a UNIX timestamp (time_t) without applying a local&lt;-&gt;UTC conversion.  UNIX_TIMESTAMP() does a UTC-&gt;local conversion, and FROM_UNIXTIME() does local-&gt;UTC.

SOLUTION:

So if your dates are stored in any timezone other than local, and you want to convert between them and UNIX timestamps, use CONVERT_TZ() with @@session.time_zone to counter balance the conversion to local.

Converting a UTC DATETIME to a (UTC) UNIX timestamp:
[code]UNIX_TIMESTAMP(CONVERT_TZ(MyDateCol, &#039;+00:00&#039;, @@session.time_zone))[/code]

Converting a (UTC) UNIX timestamp to a UTC DATETIME:
[code]CONVERT_TZ(FROM_UNIXTIME(timet), @@session.time_zone, &#039;+00:00&#039;);[/code]

SOLUTION 2:

Just stop using the DATETIME type and store your dates as UNIX timestamps in an INTEGER type.|CATEGORIES|2|DATE|1266206892