PHP date_isodate_set() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Date/Time

Definition

In PHP, date_isodate_set() changes a DateTime object to a date given as an ISO 8601 year, week number, and day of the week.

It is the procedural name for DateTime::setISODate() (and DateTimeImmutable::setISODate()). The time of day is kept as it was.

Syntax

Call date_isodate_set() with the values you need. Start with this line.

PHP
date_isodate_set($date, 2024, 10, 3);
CallWhat it does
date_isodate_set($date, 2024, 10, 3)Moves $date to Wednesday of ISO week 10 in 2024 (2024-03-06).
date_isodate_set($date, 2024, 1)Uses the default day 1 (Monday) of week 1, which is 2024-01-01.
date_isodate_set($date, 2024, 53)Week 53 does not exist in 2024, so the date rolls into the next ISO year.

ISO weeks start on Monday, and day 1 is Monday while day 7 is Sunday. The function changes the object you pass in and returns the same object. If you prefer not to change the original, use DateTimeImmutable::setISODate(), which returns a new object.

Library declarations
PHP
date_isodate_set(DateTime $object, int $year, int $week, int $dayOfWeek = 1): DateTime

Parameters

ParameterDescription
objectRequired. The DateTime object to change.
yearRequired. The ISO year number.
weekRequired. The ISO week number (1 to 52 or 53).
dayOfWeekOptional. The day of the week from 1 (Monday) to 7 (Sunday). The default is 1.

Return Value

Return ValueDescription
DateTimeThe same DateTime object after it has been changed.

PHP Examples

Example 1 — Set a Date by Week and Day

Jump to the Wednesday of week 10 in 2024. The time of day stays the same.

PHP
<?php
$date = date_create("2024-01-01 15:30:00");

date_isodate_set($date, 2024, 10, 3);
echo date_format($date, "Y-m-d H:i l"), PHP_EOL;

date_isodate_set($date, 2024, 1);
echo date_format($date, "Y-m-d H:i l"), PHP_EOL;

How It Works

  1. Create a date with a time of 15:30.
  2. date_isodate_set() with week 10 and day 3 moves the date to Wednesday, March 6, 2024.
  3. The time 15:30 is not changed.
  4. Leaving out the day uses the default of 1, which is Monday of week 1.

Example 2 — Week 53 and the ISO Year

Asking for a week that does not exist rolls over into the next ISO year.

PHP
<?php
$date = date_create("2024-06-01");

date_isodate_set($date, 2024, 53);
echo date_format($date, "Y-m-d"), PHP_EOL;
echo "ISO year: ", date_format($date, "o"), PHP_EOL;
echo "ISO week: ", date_format($date, "W"), PHP_EOL;

How It Works

  1. The ISO year 2024 has only 52 weeks, so week 53 is one week past the end.
  2. PHP moves forward and returns Monday, December 30, 2024.
  3. The format code o prints the ISO year, which is 2025 for this date.
  4. The format code W prints the week number, which is 01.

Example 3 — Find the Start and End of a Week

Use the ISO year and week of any date to get that week's Monday and Sunday.

PHP
<?php
$year = (int) date_format(date_create("2024-03-14"), "o");
$week = (int) date_format(date_create("2024-03-14"), "W");

$monday = date_create("2024-03-14");
date_isodate_set($monday, $year, $week, 1);

$sunday = date_create("2024-03-14");
date_isodate_set($sunday, $year, $week, 7);

echo "Week ", $week, " starts ", date_format($monday, "Y-m-d"), PHP_EOL;
echo "and ends ", date_format($sunday, "Y-m-d"), PHP_EOL;

How It Works

  1. Read the ISO year and week number of March 14, 2024 with the o and W format codes.
  2. Make one date object for the Monday and set its day of week to 1.
  3. Make another date object for the Sunday and set its day of week to 7.
  4. Print both dates to show the full week.

Frequently Asked Questions

It sets a DateTime object to a date described by an ISO 8601 year, week number, and day of the week. The time of day is left as it was.
Day 1 is Monday and day 7 is Sunday. This follows the ISO 8601 standard, where every week starts on Monday.
Yes. It changes the DateTime object you pass in and returns that same object. For a copy, use DateTimeImmutable::setISODate().
Y is the calendar year, and o is the ISO year. They differ in the first and last days of the year when the date belongs to a week of the neighbouring year.
Yes. It is the procedural alias of DateTime::setISODate(), which also exists on DateTimeImmutable.

Next: date_modify()

date_modify() changes a DateTime object using a relative text such as "+1 day", "next frid.

date_modify() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful