Skip to content

Instantly share code, notes, and snippets.

@bas080
Created March 4, 2019 23:53
Show Gist options
  • Save bas080/4fcc0dc9d732223d1a35157f5b78c641 to your computer and use it in GitHub Desktop.
Save bas080/4fcc0dc9d732223d1a35157f5b78c641 to your computer and use it in GitHub Desktop.
Weeks since epoch
-- Depending on what you sonsider the start of the week, you can either subtract 3 or 2 days. The week in which the epoch occured is the 0 week.
select CEIL(EXTRACT(DAYS FROM (('1970-01-04'::timestamp - '1970-01-01') - (INTERVAL '3 days'))) / 7);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment