March 18, 2012

Format and echo datetime string received from MySQL?

Question by pufAmuf

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!

Answer by Ing

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

Answer by Starx

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);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!