Skip to content

Instantly share code, notes, and snippets.

@ichux
Created October 2, 2018 03:14
Show Gist options
  • Select an option

  • Save ichux/4c573030f4dda4ccf9a075ce2daeec17 to your computer and use it in GitHub Desktop.

Select an option

Save ichux/4c573030f4dda4ccf9a075ce2daeec17 to your computer and use it in GitHub Desktop.
lists all the months in a given year interval et al
SELECT month_day1 :: DATE AS month_starts,
(month_day1 + INTERVAL '1 month' - INTERVAL '1 day') :: DATE AS month_ends,
(month_day1 + INTERVAL '1 month') :: DATE AS next_month_starts,
(month_day1 + INTERVAL '1 month') :: DATE - month_day1 :: DATE AS days
FROM generate_series(DATE '2018-01-01', DATE '2018-12-01', INTERVAL '1 month') AS month_day1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment