0

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?

David
  • 139
  • 1
  • 12
  • 2
    possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – theB Sep 17 '15 at 01:04

2 Answers2

1

I do not see how you can put the day to have the correct suffix as in 22nd or 1st. Since there is no time zone info or time offset there is no info in the string that it is GMT so if you are assuming that it is always GMT this appending the GMT at the end will work fine. Most of the time datetime is stored with an offset rather than a timezone.

<?php
 $date = date_create('2015-09-22T13:00:00');
 echo date->format('m dd, Y - g:i A').' GMT ';
?>
Bryan Hadlock
  • 2,626
  • 2
  • 17
  • 14
0

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';
?>
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Kuya
  • 7,280
  • 4
  • 19
  • 31