Skip to content
Advertisement

Reformatting a datetime field into a more readable format

I am pulling a datetime field out of a database with PHP in the form of this:

2015-09-22T13:00:00

When I populate my html with this value it returns this (note: without the ‘T’):

2015-09-22 13:00:00

No biggie.

What I’d like for the output format to look like is this:

September 22nd, 2015 – 01:00PM GMT

I can’t quite wrap my ahead around the different PHP functions as well as all the DateTime class, constants, etc etc… multiple function to switch things into different formats, not to mention the string formats for actually formatting it into the correct format.

Can someone with a little expertise help me to decipher this please?

Advertisement

Answer

If you want to get the actual GMT time then you would have to use an offset from GMT based on the user’s timezone.

If you just want to “call” it GMT then you can get your string like this…

<?php
$date = date("F jS, Y - h:i A", strtotime($row['column-name']));
echo $date.' GMT';
?>
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement