Reputation: 111
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].
Upvotes: 0
Views: 198
Reputation: 28911
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: http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format
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: https://3v4l.org/AQeTc
Upvotes: 5
Reputation: 11
You could do something like that :
$date = "2016-10-05 11:58:04";
$newDateTime = date('D, h:i A', strtotime($date));
Upvotes: 0
Reputation: 244
Should be
$dat = '2016-10-05 11:58:04';
$your_date = date("D, h:i A", strtotime($dat));
Where
D = day of the week
h = hour based on 2 x 12h day
i = minutes
A = AM or PM
function reference: http://php.net/manual/en/function.date.php
Upvotes: 1
Reputation: 118
$date = '2016-10-05 11:58:04'
$human_readable_date = date('d-M-Y H:i:s', strtodate($date))
--output : 05-Oct-2016 11:58:04
Upvotes: 0