Posted by: James Van Leuvaan | July 2, 2010

Formatting a mySQL 5.x timestamp in PHP 5.x

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

I have two specific fields in tables

   1:  creationDate > timestamp > current_timestamp
   2:  editDate > timestamp > current_timestamp

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

in mysql query i did:

   1: unix_timestamp(creationDate) AS creationDate
   2: unix_timestamp(editDate) AS editDate

in php convert i did:

   1:   $timestamp = $result_ar['creationDate'];
   2:   $creationDate = date("Y-M-d (g:i:s a)", $timestamp)
   3:      echo($creationDate);
   4:  
   5:   $editstamp = $result_ar['editDate'];
   6:   $editDate = date("Y-M-d (g:i:s a)", $editstamp)
   7:      echo($editDate);

this solved my problem for me returning

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

respectively.

I hope this helps someone out..


Categories

Follow

Get every new post delivered to your Inbox.