convert mysql timestamp to mktime

三世轮回 提交于 2019-12-24 00:43:09

问题


I have the following MySQL timestamp: 2009-06-23 16:21:48 How can I convert it to a format like mktime()?


回答1:


There is a MySQL function unix_timestamp. In your SQL query, instead of selecting the Datetime or Timestamp column directly, do this:

SELECT unix_timestamp(MyDatetimeColumn) FROM MyTable

Alternatively, if you have the string already, you could use the PHP function strtotime().




回答2:


ok, I was wrestling with this for a week (longer but i took a break from it).

I have two specific fields in tables

creationDate > timestamp > current_timestamp
editDate > timestamp > current_timestamp

they were pulling out either dec 31 1969, or just nothing... annoying... very annoying

in mysql query i did:

                unix_timestamp(creationDate) AS creationDate
                unix_timestamp(editDate) AS editDate

in php convert i did:

        $timestamp = $result_ar['creationDate'];
        $creationDate = date("Y-M-d (g:i:s a)", $timestamp)
                echo($creationDate);

        $editstamp = $result_ar['editDate'];
        $editDate = date("Y-M-d (g:i:s a)", $editstamp)
                echo($editDate);

this solved my problem for me returning

                2010-Jun-28 (5:33:39 pm)
                2010-Jun-28 (12:09:46 pm)

respectively.

I hope this helps someone out...




回答3:


You could use the strtotime function.



来源:https://stackoverflow.com/questions/1064075/convert-mysql-timestamp-to-mktime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!