• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

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

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Ranch Hand
Posts: 50
5
Oracle Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Are you here to take over the surface world? Because this tiny ad will stop you!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic