Back to Dashboard

Developer Hub

Ready-to-use snippets for your analytics. Standardize your epidemiological calculations.

R R Language

We recommend lubridate package for robust date manipulation.

CDC Standard (MMWR)

library(lubridate)

# Get current Epi Week (CDC)
epiweek(Sys.Date())

# For a specific date
epiweek(as.Date("2024-01-01"))

ISO 8601 Standard

library(lubridate)

# Get current ISO Week
isoweek(Sys.Date())

Python Python

The epiweeks package is the most complete solution for CDC standard.

CDC Standard (MMWR)

# pip install epiweeks
from epiweeks import Week, Year
from datetime import date

# Current week
week = Week.fromdate(date.today())
print(f"EW {week.week} of {week.year}")

# Iterate over weeks
for week in Year(2024).iterweeks():
    print(week.startdate(), week.enddate())

SQL SQL (PostgreSQL)

ISO 8601 Standard

-- Return week in 'IYYY-IW' format (e.g. 2024-01)
SELECT TO_CHAR(CURRENT_DATE, 'IYYY-IW');

-- Week number only
SELECT EXTRACT('week' FROM CURRENT_DATE);

Excel Excel / Google Sheets

ISO 8601 Standard

=ISOWEEKNUM(A1)

Using standard ISOWEEKNUM function.