0

Possible Duplicate:
PHP convert one date into another date format

This is PHP

I have this result:

2011-09-20 13:00:00 

I want to convert it into this format:

September 20 2011 1:00 pm

Do you know how to do that?

Anyhelp would be greatly appreciated.

Thanks!

Community
  • 1
  • 1
PinoyStackOverflower
  • 5,214
  • 18
  • 63
  • 126

8 Answers8

3

try this:

$old_date = '2011-09-20 13:00:00';
$old_date_timestamp = strtotime($old_date);
$new_date = date('F j Y g:i a', $old_date_timestamp);  
JellyBelly
  • 2,451
  • 2
  • 21
  • 41
2

If that result comes from an object of type DateTime you can use the format function:

$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');

and here all the formats you can have.. change it according to your needs.

Gianpaolo Di Nino
  • 1,139
  • 5
  • 17
1

You can get the UNIX-timestamp of a time string with strtotime() and you can get a differently designed time string with strftime()

DarkDevine
  • 1,047
  • 1
  • 9
  • 12
1

For more information you can read the documentation here : http://php.net/manual/en/function.date.php

But also is simple. Lets see how

$d = "2011-09-20 13:00:00";
$d = strtotime($d);
$d = date("F m Y g:i a", $d);
echo $d;
KodeFor.Me
  • 13,069
  • 27
  • 98
  • 166
1

Take a look at these PHP functions:

http://nl.php.net/manual/en/function.date.php

and

http://nl.php.net/strtotime

To do something like this:

date('F d Y G:i',strtotime("2011-09-20 13:00:00")); // your required format
Rene Pot
  • 24,681
  • 7
  • 68
  • 92
1

You can use this format

$date= date("F j Y g:i a");

if you have date in any variable then

$date= date("F j Y g:i a",strtotime($your_variable));

echo $date
Awais Qarni
  • 17,492
  • 24
  • 75
  • 137
1
echo date("F d Y g:i a",strtotime("2011-09-20 13:00:00 "));
SW4
  • 69,876
  • 20
  • 132
  • 137
1

echo date('F d Y g:i a', strtotime('2011-09-20 13:00:00'));

check the date format

xdazz
  • 158,678
  • 38
  • 247
  • 274