-7

I have the creation time in following format: Mon Mar 25 2013 15:28:21 GMT+0000 (GMT Standard Time) How can I use PHP to extract the date from this string?

user1369905
  • 663
  • 2
  • 7
  • 12

2 Answers2

4
$dateTime = DateTime::createFromFormat('D M d Y H:i:s e', 'Mon Mar 25 2013 15:28:21 GMT+0000');
$dateTime->setTimezone(new DateTimeZone('UTC'));

echo $dateTime->format('Y-m-d H:i:s');

Note this requires at least PHP 5.3.0, for more information see documentation at http://www.php.net/manual/en/datetime.createfromformat.php

Barry Staes
  • 3,890
  • 4
  • 24
  • 30
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
0

See http://php.net/manual/en/function.date-parse.php

Example #1 A date_parse() example

<?php
print_r(date_parse("2006-12-12 10:00:00.5"));
?>

The above example will output:

Array
(
    [year] => 2006
    [month] => 12
    [day] => 12
    [hour] => 10
    [minute] => 0
    [second] => 0
    [fraction] => 0.5
    [warning_count] => 0
    [warnings] => Array()
    [error_count] => 0
    [errors] => Array()
    [is_localtime] => 
)

From here on, you should be able to parse Mon Mar 25 2013 15:28:21 GMT+0000. Or consider using explode(' ', $parts) to split it into a $parts[2]='25' array.

Barry Staes
  • 3,890
  • 4
  • 24
  • 30