Canman2005 Posted April 20, 2007 Share Posted April 20, 2007 Hi all I have a database which holds news, with each news article it has two fields start_date and end_date, these dates are stored as 2007-01-02 (YYYY-MM-DD) I currently use the following query for my main news page SELECT * FROM mynews WHERE area='1' AND live = '1' ORDER BY id DESC What I want to do is to write a new page where it can show old news, this would only show news that has the end_date which is past todays current date. Additionally to this, I want to show just the last 2 months worth of news. How can I ask it to just query rows with an end_date which has past, but only for 2 months. Does that make sense? Can anyone help? Thanks Ed Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 20, 2007 Share Posted April 20, 2007 I suggest storing dates as unix timestamps. You can easily compare records with a unix timestamp of 2 months ago. It's also faster for the database as your data type will be int instead of string. Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted April 20, 2007 Author Share Posted April 20, 2007 Problem is that there is 20,000 records and changing them would be out of the picture, is there a solution with my method? Quote Link to comment Share on other sites More sharing options...
per1os Posted April 20, 2007 Share Posted April 20, 2007 20,000 records is all? lol that would only take a minute or less =) Anyhow the function you are looking for would be www.php.net/strtotime That should help you out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.