How do convert RSS feed publish date-time (GMT) to Unix timestamp using PHP?
I need to store the date into my table in a TIMESTAMP
data type column.
How do convert RSS feed publish date-time (GMT) to Unix timestamp using PHP?
I need to store the date into my table in a TIMESTAMP
data type column.
From MySQL Manual:
TIMESTAMP columns are displayed in the same format as DATETIME columns. In other words, the display width is fixed at 19 characters, and the format is 'YYYY-MM-DD HH:MM:SS'.
The RSS 2.0 specification states that:
All date-times in RSS conform to the Date and Time Specification of RFC 822, with the exception that the year may be expressed with two characters or four characters (four preferred).
So if we have the following RSS date:
$timeRSS = 'Sat, 07 Sep 2002 09:42:31 GMT'; // RFC 822
We need to do the following to convert it to MySQL TIMESTAMP
format:
date_default_timezone_set('GMT'); // make sure we are using the same timezone
date('Y-m-d H:i:s', strtotime($timeRSS)); // 2002-09-07 09:42:31
Would it be an option to use the PHP functions to generate a Unix Timestamp (ie seconds since Unix Epoch) and then let MySQL handle it from there?
PHP: - PHP Documentation
$timestamp = strtotime( 'Sat, 07 Sep 2002 09:42:31 GMT' ); // = 1031391751
MySQL: - MySQL Documentation
... `timestamp` = FROM_UNIXTIME( 1031391751 ) ...