2

Say I have a startdate = '2010/04/01' and an enddate = '2011/02/01'.

How would I set up a query such that I retrieve the following table as a response:

month
2010/04/01
2010/05/01
2010/06/01
2010/07/01
2010/08/01
2010/09/01
2010/10/01
2010/11/01
2010/12/01
2011/01/01
2011/02/01

Note that I'm not too fussed about the format, anything that works will do.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Bilal Akil
  • 4,716
  • 5
  • 32
  • 52

1 Answers1

5

PostgreSQL has generate_series() to make that an easy task:

SELECT generate_series('2010-04-01', '2011-02-01', interval '1 month')::date
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228