Skip to content

Instantly share code, notes, and snippets.

@adeishs
Created September 30, 2022 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeishs/1d1c1c5fe6b23087abbcc2e66bedaf9e to your computer and use it in GitHub Desktop.
Save adeishs/1d1c1c5fe6b23087abbcc2e66bedaf9e to your computer and use it in GitHub Desktop.
Get the first Monday of a year
-- 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