I am loading articles from RSS and there is the date value formatted in various as:
January 4, 2013
Fri, 04 Jan 2013 13:18:05 +0000
Fri, 04 Jan 2013 07:33:51 EST
Jan 4, 2013
Fri, 04 Jan 2013 02:27:46 GMT
Is there any uniform way, how to save these values into the database column with datatype DATETIME
, TIMESTAMP
or TIME
, which is the most appropriate for sorting these articles?
You can try like this-
echo date("Y-m-d H:i:s",strtotime("January 4, 2013")); // 2013-01-04 00:00:00
echo date("Y-m-d H:i:s",strtotime("Fri, 04 Jan 2013 13:18:05 +0000")); //2013-01-04 13:18:05
echo date("Y-m-d H:i:s",strtotime("Fri, 04 Jan 2013 07:33:51 EST")); //2013-01-04 12:33:51
echo date("Y-m-d H:i:s",strtotime("Jan 4, 2013")); //2013-01-04 00:00:00
echo date("Y-m-d H:i:s",strtotime("Fri, 04 Jan 2013 02:27:46 GMT")); //2013-01-04 02:27:46
updated datetime format.
Use strtotime
function. http://php.net/manual/en/function.strtotime.php
date("Y-m-d H:i:s", strtotime($dateString));