Mysql 函數使用記錄(三)——UNIX_TIMESTAMP() 、UNIX_TIMESTAMP(date)
參考資料:https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_unix-timestamp
UNIX_TIMESTAMP() :returns a Unix timestamp (seconds since ‘1970-01-01 00:00:00‘
UTC). ——自‘1970-01-01 00:00:00‘的到當前時間的秒數差
例:
SELECT UNIX_TIMESTAMP(); ====> 1507520072
UNIX_TIMESTAMP(date) : it returns the value of the argument as seconds since ‘1970-01-01 00:00:00‘
1>.The date
argument may be a DATE
, DATETIME
, or TIMESTAMP
string, or a number in YYMMDD
, YYMMDDHHMMSS
, YYYYMMDD
, or YYYYMMDDHHMMSS
format.
其中date可以是一個DATE,DATETIME或者TIMESTAMP的字符串,也可以是YYMMDD,YYMMDDHHMMSS,YYYYMMDD或YYYYMMDDHHMMSS格式的數字。
例:
SELECT UNIX_TIMESTAMP(‘2017-10-8 08:08:08‘); ====> 1507421288
SELECT UNIX_TIMESTAMP(CURRENT_DATE()); ====> 1507478400
SELECT UNIX_TIMESTAMP(NOW()); ====> 1507520319
註:CURRENT_DATE ()的返回值是一個DATE字符串格式;NOW()的返回值是一個DATETIME字符串格式
Mysql 函數使用記錄(三)——UNIX_TIMESTAMP() 、UNIX_TIMESTAMP(date)