verdrm Posted February 24, 2008 Share Posted February 24, 2008 Is there a way to SELECT data WHERE date is closest to today's date? I use the following to format dates: $date = date("D, M dS, Y"); Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted February 24, 2008 Share Posted February 24, 2008 i think it'd be easier if you used NOW() instead of a custom date. Quote Link to comment Share on other sites More sharing options...
verdrm Posted February 24, 2008 Author Share Posted February 24, 2008 OK, but how does that help me if I want to retrieve, let's say, 5 records closest to today's date? OR--better thought, what about 5 records with the highest ID...so instead of by date what about by the auto_increment ID? Quote Link to comment Share on other sites More sharing options...
tapos Posted February 24, 2008 Share Posted February 24, 2008 Use 'order by' to sort out the data according the date then use LIMIT to take just 5 row. Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted February 24, 2008 Share Posted February 24, 2008 well if you inserted NOW() you can either: mysql_query("SELECT * FROM table WHERE date > (NOW() - INTERVAL 10 DAY)") // retrieves entries from last 10 days or mysql_query("SELECT * FROM table ORDER BY date DESC LIMIT 10") // retrieves last 10 entries Quote Link to comment Share on other sites More sharing options...
Barand Posted February 24, 2008 Share Posted February 24, 2008 If this is the date format in your table $date = date("D, M dS, Y"); then it's totally useless for any sort or date comparison 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.