File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Get date List between two dates in mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Get date List between two dates in mysql" Watch "Get date List between two dates in mysql" New topic
Author

Get date List between two dates in mysql

Ramasubramaniam Rathinasubbu
Ranch Hand

Joined: Jun 09, 2010
Posts: 44
I want to get date list between two dates like
1-May-2011 to 7-May-2011

result should be

1-May-2011
2-May-2011
3-May-2011
4-May-2011
5-May-2011
6-May-2011
7-May-2011


thanks,
R. Ramasubramaniam.

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

There must be some keyword in SQL that lets you find things between two values...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hi,

You haven't given us any information on the table that you are trying to query to get the results you want. You would probably use BETWEEN in your SQL, maybe a GROUP BY but you will have to give us some more information.

Sean


I love this place!
Ramasubramaniam Rathinasubbu
Ranch Hand

Joined: Jun 09, 2010
Posts: 44
no tables, just if we give two dates, i need list of dates.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Why would you want to to that?

To answer your question I don't know how you would do that, though I guess it would be possible (maybe using T-SQL - but I really don't know)

Sean
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I have to agree with Sean here - what has MySQL to do with this?
Rudy Gireyev
Ranch Hand

Joined: May 03, 2011
Posts: 39
Ramasubramaniam Rathinasubbu wrote:no tables, just if we give two dates, i need list of dates.
You will probably get much better answers and certainly more attention to your posts if you post them in the right forum. Here's a link to a forum where you can ask general JAVA questions.

Anyway, it is not at all clear from your post what you are looking for, but just in case I understood what you after here's my proposal for a solution:
// First create 3 instances of a Calendar date, one to hold you start date, one to hold your end date and one to hold tha dates in between as they are generated inside the loop
Calendar startDate = Calendar.getInstance();
Calendar endDate = Calendar.getInstance();
Calendar currDate = Calendar.getInstance();

// Next set each object to the desired date. The startDate and currDate will be set to the same value
startDate.set(2011, 5, 1);
endDate.set(2011, 5, 7);
currDate.set(2011, 5, 1);

// Now create the loop that will generate the desired list of dates
while (currDate.equals(endDate) == false)
{
currdate.add(Calendar.DAY_OF_MONTH, 1);
}

You will probably want a DateFormat class to make your date appear human readable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get date List between two dates in mysql
 
Similar Threads
adding or in criteria query
Displaying tha Date between two dates in paint method...
dates between two dates
Invalid field value for field "Date"
What is the Data Type for GMT Date and Time?