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);
Call
What 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
Parameter
Description
object
Required. The DateTime object to change.
year
Required. The ISO year number.
week
Required. The ISO week number (1 to 52 or 53).
dayOfWeek
Optional. The day of the week from 1 (Monday) to 7 (Sunday). The default is 1.
Return Value
Return Value
Description
DateTime
The 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.
Read the ISO year and week number of March 14, 2024 with the o and W format codes.
Make one date object for the Monday and set its day of week to 1.
Make another date object for the Sunday and set its day of week to 7.
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.