Skip to content

Instantly share code, notes, and snippets.

@ianthrive
Created October 19, 2012 11:07
Show Gist options
  • Save ianthrive/3917612 to your computer and use it in GitHub Desktop.
Save ianthrive/3917612 to your computer and use it in GitHub Desktop.
SQL: list all days in a month given a date within that month
PREPARE test AS
WITH RECURSIVE T(n) AS (
SELECT date_trunc('month', $1::date)::date AS start
UNION
SELECT n+1 FROM T WHERE n < date_trunc('month', $1)::date + '1 month'::interval - '1 day'::interval
)
SELECT * FROM T;
EXECUTE test('15 nov 2012');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment