MySQL DateTime 實例可以透過UNIX_TIMESTAMP() 函數以下列方式轉換為秒-
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)
以上查詢會將給定的日期時間實例轉換為總秒數。
mysql> Select UNIX_TIMESTAMP(NOW()) AS 'NUMBER OF SECONDS'; +-------------------+ | NUMBER OF SECONDS | +-------------------+ | 1509248856 | +-------------------+ 1 row in set (0.00 sec)
以上查詢會將目前的 DateTime 實例轉換為總秒數。
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)
以上查詢將轉換 DateTime 實例,該實例是表格「testing」中的儲存值,其中列 StudentName 的值為「Gaurav」。
以上是如何從 MySQL DATETIME 實例取得總秒數?的詳細內容。更多資訊請關注PHP中文網其他相關文章!