view raw
Draeko Draeko - 7 months ago 43
PHP Question

display DateTime format into readable string in PHP

i have a stored DateTime with this format [2016-10-05 11:58:04]. What i want to do is, display the stored time into this readable format [Wed, 11:58 AM].


Since you tagged your question with mysqli and php here are solutions for both:


You can format the date directly in your query:

select DATE_FORMAT(column_name, "%a, %h:%i %p") AS formatted_date FROM table_name

See docs:


If you have this string and need to format it in PHP, use DateTime:

$dt = new DateTime("2016-10-05 11:58:04");
echo $dt->format("D, h:i A"); // Wed, 11:58 AM

Working example: