Skip to content

Instantly share code, notes, and snippets.

@niczero
Last active April 10, 2017 09:13
Show Gist options
  • Save niczero/46fd5f65f335458d49f1415938f7f908 to your computer and use it in GitHub Desktop.
Save niczero/46fd5f65f335458d49f1415938f7f908 to your computer and use it in GitHub Desktop.
Group into 4-week periods (in MySQL)
SET @day = CURDATE();
SELECT FLOOR(DATEDIFF(DATE_SUB(@day, INTERVAL DAYOFWEEK(@day) DAY), '1970-01-01') / 28) AS FWP
-- 1970-01-04 is the start of FWP 0
SELECT FLOOR((TO_DAYS(@day) - TO_DAYS('1970-01-04') + 0.01) / 28) AS FWP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment