RSS feed publishes datetime (GMT) in Unix timestamp format using PHP

How to convert RSS feed publish date and time (GMT) to Unix timestamp using PHP?

I need to store a date in my table in a datatype column TIMESTAMP

.

+2


a source to share


2 answers


Is it possible to use PHP functions to create a Unix timestamp (i.e. seconds since Unix Epoch) and then let MySQL process it from there?

PHP: - PHP Documentation

$timestamp = strtotime( 'Sat, 07 Sep 2002 09:42:31 GMT' ); // = 1031391751

      



MySQL: - MySQL Documentation

... `timestamp` = FROM_UNIXTIME( 1031391751 ) ...

      

+4


a source


From MySQL Manual :

TIMESTAMP tables are displayed in the same format as DATETIME columns. In other words, the screen width is fixed at 19 characters, and the format is "YYYY-MM-DD HH: MM: SS".

the RSS 2.0 specification states that:

All dates in RSS conform to the RFC 822 Date and Time Specification, except that the year can be expressed in 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 format TIMESTAMP

:

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

      

+2


a source







All Articles