Php – convert any date string to timestamp without timezone

datetimePHPpostgresqlsql

I'm getting xml and rss feeds and putting the data into a database. I've run into two different date formats so far…

Wed, 21 Jul 2010 00:28:50 GMT

And

2010-07-20T17:33:19Z

I'm sure there will be more. My postgresql database for the date is timestamp without time zone. Is there an existing function in php or is there a procedure to convert the any date strings to timestamp without time zone (Y-m-d H:i:s)?

Best Answer

Use date with strtotime:

$date = date('Y-m-d H:i:s', strtotime('Wed, 21 Jul 2010 00:28:50 GMT'));
echo $date;

Result:

2010-07-21 05:28:50

.

$date = date('Y-m-d H:i:s', strtotime('2010-07-20T17:33:19Z'));
echo $date;

Result:

2010-07-20 22:33:19