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
  • 4,996
  • 14
  • 53
  • 121

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,443
  • 2
  • 20
  • 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,039
  • 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
  • 12,429
  • 26
  • 92
  • 160
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,003
  • 7
  • 67
  • 90
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
  • 16,276
  • 23
  • 74
  • 134
1
echo date("F d Y g:i a",strtotime("2011-09-20 13:00:00 "));
SW4
  • 67,554
  • 20
  • 126
  • 133
1

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

check the date format

xdazz
  • 154,648
  • 35
  • 237
  • 264