UNIX_TIMESTAMP()
UNIX_TIMESTAMP(date)
If called with no argument, returns a Unix timestamp (seconds since
'1970-01-01 00:00:00' GMT) as an unsigned integer. If UNIX_TIMESTAMP() is
called with a date argument, it returns the value of the argument as
seconds since '1970-01-01 00:00:00' GMT. date may be a DATE string, a
DATETIME string, a TIMESTAMP, or a number in the format YYMMDD or YYYYMMDD
in local time.
mysql> SELECT UNIX_TIMESTAMP();
-> 882226357
mysql> SELECT UNIX_TIMESTAMP('1997-10-04 22:23:00');
-> 875996580
When UNIX_TIMESTAMP is used on a TIMESTAMP column, the function returns
the internal timestamp value directly, with no implicit
``string-to-Unix-timestamp'' conversion. If you pass an out-of-range date
to UNIX_TIMESTAMP(), it returns 0, but please note that only basic range
checking is performed (year from 1970 to 2037, month from 01 to 12, day
from 01 from 31). If you want to subtract UNIX_TIMESTAMP() columns, you
might want to cast the result to signed integers. See section 13.7 Cast
Functions.
I'm specifically interested in why this behaviour was decided upon:
When UNIX_TIMESTAMP is used on a TIMESTAMP column, the function returns the
internal timestamp value directly, with no implicit
``string-to-Unix-timestamp'' conversion.
Is it just me or is MySQL lacking a timestamp-to-unixtimestamp conversion?
--
Donovan Hill
Linux User, Canadian.... All around nice guy!
All email to the reply-to address above will automatically put your IP in a
blocklist and qualify you for a free security audit.