1.20.x date.inc date_iso_week_range($week, $year)

Calculates the start and end dates for an ISO week.

See https://en.wikipedia.org/wiki/Week#Week_numbering.


int $week: The week value.

int $year: The year value.

Return value

array: A numeric array containing the start and end dates of an ISO week.


includes/date.inc, line 978
Date API functions and constants.


function date_iso_week_range($week, $year) {
  // Get to the last ISO week of the previous year.
  $min_date = new BackdropDateTime(($year - 1) . '-12-28 00:00:00');
  date_timezone_set($min_date, date_default_timezone_object());

  // Find the first day of the first ISO week in the year.
  date_modify($min_date, '+1 Monday');

  // Jump ahead to the desired week for the beginning of the week range.
  if ($week > 1) {
    date_modify($min_date, '+ ' . ($week - 1) . ' weeks');

  // Move forwards to the last day of the week.
  $max_date = clone($min_date);
  date_modify($max_date, '+6 days');
  return array($min_date, $max_date);