Last active
August 29, 2015 14:06
-
-
Save ianthrive/41e68400e140f60a2d33 to your computer and use it in GitHub Desktop.
Calculates and returns the Nth day of the week for the given date.
This file contains 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
CREATE OR REPLACE FUNCTION public.extract_nth_dow(d date) RETURNS integer | |
AS $$ | |
-- Calculates and returns the Nth day of the week for the given date. | |
SELECT (EXTRACT(day FROM d)::INTEGER - 1) / 7 + 1; | |
$$ LANGUAGE sql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment