How to convert DateTime to a number in MySQL?

后端 未结 4 622
再見小時候
再見小時候 2020-12-31 05:40

How can I get the total number of seconds since \'1970-01-01 00:00:01\' from a DateTime instance in MySQL?

4条回答
  •  心在旅途
    2020-12-31 06:25

    You are looking for UNIX_TIMESTAMP().

    See: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp

    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.

提交回复
热议问题