Created
September 30, 2022 00:11
-
-
Save adeishs/1d1c1c5fe6b23087abbcc2e66bedaf9e to your computer and use it in GitHub Desktop.
Get the first Monday of a year
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
-- get the first Monday of a year | |
WITH year AS ( | |
-- change the year as you need | |
SELECT CAST(2022 AS INTEGER) y | |
), | |
first_date AS ( | |
SELECT CAST(y || '-01-01' AS DATE) AS d | |
FROM year | |
) | |
SELECT d + (8 - CAST(EXTRACT(DOW FROM d) AS INTEGER)) % 7 | |
FROM first_date; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment