-2

Possible Duplicate:
how to convert php date formats to GMT and vice versa?

In PHP, I have a string date like this:

May 21, 2012 07:23:15 GMT

or this

21 May 2012 07:23:15 GMT

I need to convert both the strings into something like this: 21-05-2012. (day-month-year)

Can PHP correctly parse both these strings into a day-month-year format?

Community
  • 1
  • 1
Dmitry Makovetskiyd
  • 6,942
  • 32
  • 100
  • 160

4 Answers4

3

Try This -

 $your_string = "21 May 2012 07:23:15 GMT";
 $dd = date("d-m-Y", strtotime($your_string));
 echo $dd;
Botz3000
  • 39,020
  • 8
  • 103
  • 127
swapnesh
  • 26,318
  • 22
  • 94
  • 126
2

Have you tried the DateTime class?

date_default_timezone_set('Europe/Stockholm');
$date = new DateTime("May 21, 2012 07:23:15 GMT");
print $date->format('Y-m-d');
h00ligan
  • 1,471
  • 9
  • 17
1

You could use strtotime() for this. Alternatively, if you know what format to expect, you can use strptime() to parse it, which would be preferred.

rid
  • 61,078
  • 31
  • 152
  • 193
0

Try this

$str_date = "May 21, 2012 07:23:15 GMT";
$date = DateTime::createFromFormat('M d, Y H:i:s O', $str_date);
echo  $date->format('d-m-Y');
bitoshi.n
  • 2,278
  • 1
  • 16
  • 16