I am trying to generate a series of dates by week from March 1st, 2013 at 00:00:00 to March 14, 2013 at 23:59:59. The query that I have until now looks like this
SELECT GREATEST(date_trunc('week', dates.d),
date_trunc('month',dates.d)) as start
FROM generate_series(to_timestamp(1362096000),
to_timestamp(1363305599), '1 week') as dates(d)
Output:
start
------------------------
2013-03-01 00:00:00+00
2013-03-04 00:00:00+00
The query partially works because it returns the first two weeks as you can see but it's missing the week from March 11, 2013 to March 14, 2013. Is there any way to get the last week even though it has not ended?