Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get date List between two dates in mysql

 
Ramasubramaniam Rathinasubbu
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There must be some keyword in SQL that lets you find things between two values...
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ramasubramaniam Rathinasubbu
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no tables, just if we give two dates, i need list of dates.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to agree with Sean here - what has MySQL to do with this?
 
Rudy Gireyev
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic