Formatting an SQL timestamp with PHP

后端 未结 6 548
無奈伤痛
無奈伤痛 2020-12-01 16:15

I have a mySQL database with a timestamp field. It currently only has one entry while I\'m testing, it is

2010-02-20 13:14:09

I am pulling

6条回答
  •  孤城傲影
    2020-12-01 16:34

    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..

提交回复
热议问题