Created
October 19, 2012 11:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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