MySQL: how do you convert a datetime to unix time?
can I do thi开发者_StackOverflow中文版s is a query?
See the UNIX_TIMESTAMP()
function.
This can be done in MySQL by using UNIX_TIMESTAMP() or UNIX_TIMESTAMP(date).
If called with no argument, this returns a Unix timestamp (seconds since '1970-01-01 00:00:00' UTC) 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' UTC.
mysql> SELECT UNIX_TIMESTAMP();
-> 1196440210
mysql> SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19');
-> 1196440219
use the UNIX_TIMESTAMP()
function.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp
精彩评论