Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format and echo datetime string received from MySQL?

Tags:

php

how would I format a datetime string received from MySQL? For example, when I do

echo $info['start_datetime']

I get 2012-03-18 21:00:00, but I would like to Turn it into Sunday, March 18, 2012. I looked at the php documentation where it showed the different formats, but not specifically when they're retrieved from MySQL.

Thanks everyone!

like image 813
pufAmuf Avatar asked Dec 04 '25 22:12

pufAmuf


2 Answers

echo date('l, F d, Y', strtotime($info['start_datetime']));

There are load of ways you can format the date. First change the time into timestamp using strtotime() function.

Check this page to get the list of how to format a date.

The usage is something like this

$time = strtotime($info['start_datetime']);
echo date("l, F d, Y", $time);
like image 34
Starx Avatar answered Dec 07 '25 14:12

Starx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!