I need to get data from RSS feed and then save it to MySQL. The problem is that in RSS feed datetime format is like this: Sun, 09 Nov 2014 12:00:38 +0200
How I could convert it to format so I could save it to database? and how to convert it back later when I want to display it again with the same format?
Asked
Active
Viewed 342 times
0

Einius
- 1,352
- 2
- 20
- 45
-
possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – vascowhite Nov 09 '14 at 10:11
-
Also http://stackoverflow.com/questions/2487921/convert-date-format-yyyy-mm-dd-dd-mm-yyyy – vascowhite Nov 09 '14 at 10:15
2 Answers
2
Try this
$DateTime= date("Y-m-d H:i:s", strtotime("Sun, 09 Nov 2014 12:00:38 +0200"));
echo $DateTime;
To retrieve back from db, in your select query use
DATE_FORMAT(date_column, '%a %d %b %Y %T')

Indra Kumar S
- 2,818
- 2
- 16
- 27
-
-
-
-
In that case you might want to mention STR_TO_DATE('2011-12-21 02:20pm', '%Y-%m-%d %h:%i%p') also – Frankey Nov 09 '14 at 10:21
0
if you are using PHP along with MySQL, strtotime() is nice php function :)
http://php.net/manual/en/function.strtotime.php
date_default_timezone_set('UTC');
$date_string = 'Sun, 09 Nov 2014 12:00:38 +0200';
echo 'original string: '.$date_string.'<br/>';
$unix_time_stamp = strtotime($date_string );
echo 'timestamp: '.$unix_time_stamp.'<br/>';
$old_format = date("D, j M Y H:i:s O", $unix_time_stamp );
echo 'back to originalt: '.$old_format;
Example on http://viper-7.com/KI5LfG
You can get any date format you desire with php date()

Frankey
- 3,679
- 28
- 25