Jump to content

Sort by date help


ferret147

Recommended Posts

as you will already know when you store the date in a database it is like this 0000-00-00 00:00:00

 

What I am doing is storing blog (wordpress) post and Tweets into a database and saving the titles, description and pubDate data from the RSS feeds.

 

My problem is that the dates in the RSS feeds are formatted like this - Fri, 27 Aug 2010 11:37:28 +0000 so when I try to display this data on a php page date and time posted I can not.

 

Is there a way to use the format Fri, 27 Aug 2010 11:37:28 +0000 and sort it by date and time posted when retrieving form the database or am I going to have to do some coding to format Fri, 27 Aug 2010 11:37:28 +0000 onto 0000-00-00 00:00:00 when initially entering the data into the database ?

 

Any advice would be greatly appreciated.

Link to comment
Share on other sites

Indeed this is what I am trying to achieve, have a look at the URL's I have put below, you will have to view the source code and find the pubDate of each item.

 

Wordpress example - http://bestblog.wordpress.com/feed/

Twitter Example - http://twitter.com/statuses/user_timeline/14230524.rss

 

My script gets the contents of 20 blogs and 20 Tweeters every 5 minutes and puts them all into a database and I want to be able to then display these database entries sorted by the time and date they were originally posted.

 

So if Twitter and Wordpress do not format the dates properly in the first place how am I to sort then :( !!!

 

It either has to be before I inject into my database or on retrieval when I put the results into my php page but which one and how!

 

I knew this was going to be a tricky one when I started but did not realise it would be this difficuly to reformat a date :(

Link to comment
Share on other sites

The field's data type should be DATETIME.

 

As far as formatting it, for the example you gave (assuming you're using PHP 5.2 or greater), this would format the date correctly.

 

<?php
$date = 'Fri, 27 Aug 2010 11:37:28 +0000';
$formatted = date_format(date_create($date), 'Y-m-d H:i:s');
echo $formatted;
// RETURNS '2010-08-27 11:37:28'
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.