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?
-
possible duplicate of Convert one date format into another in PHPvascowhite– vascowhite2014-11-09 10:11:17 +00:00Commented Nov 9, 2014 at 10:11
-
Also stackoverflow.com/questions/2487921/…vascowhite– vascowhite2014-11-09 10:15:58 +00:00Commented Nov 9, 2014 at 10:15
Add a comment
|
2 Answers
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')
4 Comments
Mark Zucchini
What about convert it to back Sun, 09 Now 2014... ?
Indra Kumar S
You want to get it from db in Sun,09 Nov 2014 format ?
Mark Zucchini
That's what asked in question.
Frankey
In that case you might want to mention STR_TO_DATE('2011-12-21 02:20pm', '%Y-%m-%d %h:%i%p') also
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()