MySQL DateTime 實(shí)例可以通過 UNIX_TIMESTAMP() 函數(shù)按以下方式轉(zhuǎn)換為秒 –
mysql> Select UNIX_TIMESTAMP('2017-05-15 04:05:30') AS 'NUMBER OF SECONDS'; +-------------------+ | NUMBER OF SECONDS | +-------------------+ | 1494801330 | +-------------------+ 1 row in set (0.00 sec)
登錄后復(fù)制
以上查詢會(huì)將給定的日期時(shí)間實(shí)例轉(zhuǎn)換為總秒數(shù)。
mysql> Select UNIX_TIMESTAMP(NOW()) AS 'NUMBER OF SECONDS'; +-------------------+ | NUMBER OF SECONDS | +-------------------+ | 1509248856 | +-------------------+ 1 row in set (0.00 sec)
登錄后復(fù)制
以上查詢會(huì)將當(dāng)前的 DateTime 實(shí)例轉(zhuǎn)換為總秒數(shù)。
mysql> Select UNIX_TIMESTAMP(Dateofreg) AS 'NUMBER OF SECONDS' from testing where StudentName = 'Gaurav'; +-------------------+ | NUMBER OF SECONDS | +-------------------+ | 1509247113 | +-------------------+ 1 row in set (0.00 sec)
登錄后復(fù)制
以上查詢將轉(zhuǎn)換 DateTime 實(shí)例,該實(shí)例是表“testing”中的存儲(chǔ)值,其中列 StudentName 的值為“Gaurav”。
以上就是如何從 MySQL DATETIME 實(shí)例獲取總秒數(shù)?的詳細(xì)內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!