Created
June 27, 2017 04:36
-
-
Save ianthrive/e62d964d299cfcf12f23b5c588b8b302 to your computer and use it in GitHub Desktop.
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 first_dow_of_month(year INTEGER, month INTEGER, dow INTEGER) | |
RETURNS date LANGUAGE plpgsql | |
AS $$ | |
DECLARE | |
first_day DATE := (year||'-'||month||'-1')::DATE; | |
first_day_plus_week DATE := first_day + '1 week'::INTERVAL; | |
BEGIN | |
RETURN first_day_plus_week + dow - DATE_PART('dow', first_day_plus_week)::INTEGER; | |
END; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment