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 how to write a sql producing data ranges from a given date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to write a sql producing data ranges from a given date" Watch "how to write a sql producing data ranges from a given date" New topic
Author

how to write a sql producing data ranges from a given date

Grace Russo
Ranch Hand

Joined: Nov 08, 2010
Posts: 64
Hi,

I am not an expert in SQL, and I need to figure out the following:
- given a start date, output the 12 months date ranges until the date range that includes today

For instance, the start date is 10 June 2010, the date range I should produce would be
10 June 2010-10 June 2011
10 June 2011-10 June 2012
10 June 1012-10 June 2013
10 June 2013-10 June 2014 <--- this includes today's date of 1 July 2013.

Could anyone help ?
Thank you !
Lukas Eder
Ranch Hand

Joined: Jul 22, 2013
Posts: 41
    
    4

First off, what database is this for?

In Oracle, you could use CONNECT BY to generate records for all dates between a given input date and today:



See this SQL Fiddle here for details:
http://sqlfiddle.com/#!4/d41d8/14448


When Java and SQL work together, great software can evolve. That's why I have created jOOQ. Follow me on blog.jooq.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to write a sql producing data ranges from a given date
 
Similar Threads
Java Hashset remove duplicates
Java Calendar Dates
Restrictions Between for Date in Hibernate Criteria
to understand which *.MF to use
Java Calendar Dates