All pastes #386742 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-03-08 21:20 UTC
rendered paste body
Anonymous@user
23-Feb-2006 12:15 
The previous note is correct: UNIX_TIMESTAMP assumes that the value in a
DATETIME field is local time - that is, the time set by the "SYSTEM"
time variable. However, here's a workaround I've found:

SELECT UNIX_TIMESTAMP (
CONVERT_TZ (my_datetime_column, '+0:00', 'SYSTEM'));

CONVERT_TZ converts the value of "my_datetime_column" to the system's
local time; UNIX_TIMESTAMP converts it back to Greenwich time, and
returns the time in UNIX epoch time.

This is a little convoluted, but it works.