How can I format a timestamp from MySQL to a date value in PHP?
3
-
2(hint) How a date is formatted has nothing to do with how it is represented internally or how it is stored.Gordon– Gordon2011-06-03 14:30:46 +00:00Commented Jun 3, 2011 at 14:30
-
1If mysql formatting isn't enough for you, then you can use SELECT UNIX_TIMESTAMP(datecolumn) ... to get a unix timestamp for use in php's date() function. Would be a lot more optimal than parsing it with strtotime that they used in the answers below.jishi– jishi2011-06-03 14:41:38 +00:00Commented Jun 3, 2011 at 14:41
-
Thank you for the suggestion. That's probably the way to go. You could add this to the answers if you'd like me to accept it.Chalise– Chalise2011-06-03 14:44:04 +00:00Commented Jun 3, 2011 at 14:44
Add a comment
|
2 Answers
echo date('r', strtotime($mysql_datetime_column_value));
See the date() function in the PHP documentation for more detail.