Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2007, 08:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default selecting date and previous dates

I have a database with an event date. I need to select the latest date and the varying amount dates previous to this. I came up with this but was
wondering if there would be a more efficient way to do this.

SELECT display_date FROM myDB WHERE display_date
BETWEEN SUBDATE((SELECT MAX(display_date) FROM myDB), INTERVAL 10 DAY)
AND (SELECT MAX(display_date) FROM myDB)
ORDER BY display_date

Example: Data in database
2004-05-27 00:00:00
2004-05-25 00:00:00
2004-05-26 00:00:00

2006-09-27 00:00:00
2006-09-25 00:00:00
2006-09-29 00:00:00
2006-09-28 00:00:00

2005-09-26 00:00:00
2005-09-25 00:00:00
2005-09-27 00:00:00
2005-09-28 00:00:00

Content Needed To Display and ordering
2006-09-25 00:00:00
2006-09-27 00:00:00
2006-09-28 00:00:00
2006-09-29 00:00:00

Many Thanks
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Previous Date in vb.net kostaskir VB How-To 1 August 31st, 2007 09:21 AM
Needs to get previous date from the given date balakrishna Java Basics 1 April 23rd, 2007 05:25 AM
How to get previous date? rupen Javascript How-To 1 June 26th, 2006 10:57 PM
Problem with selecting data between two dates serf SQL Language 1 January 18th, 2006 01:16 PM
Selecting Data Based on Todays Date worshiploud Classic ASP Basics 2 June 29th, 2003 07:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.