0

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?

2

2 Answers 2

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')
Sign up to request clarification or add additional context in comments.

4 Comments

What about convert it to back Sun, 09 Now 2014... ?
You want to get it from db in Sun,09 Nov 2014 format ?
That's what asked in question.
In that case you might want to mention STR_TO_DATE('2011-12-21 02:20pm', '%Y-%m-%d %h:%i%p') also
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()

http://php.net/manual/en/function.date.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.