The setISODate Method of the DateTime Class
The setISODate
method sets the date in the DateTime
object according to the ISO 8601 standard, using the week number and the day of the week. The first parameter is the year, the second is the week number, and the third is the day of the week (from 1 to 7, where 1 is Monday).
Syntax
$datetime->setISODate(year, week, day);
Example
Let's set the date for the 10th week of 2023, Thursday (day of the week 4):
<?php
$date = new DateTime();
$date->setISODate(2023, 10, 4);
echo $date->format('Y-m-d');
?>
Code execution result:
'2023-03-09'
Example
Let's set the date only by the week number (the day of the week will be Monday by default):
<?php
$date = new DateTime();
$date->setISODate(2023, 10);
echo $date->format('Y-m-d');
?>
Code execution result:
'2023-03-06'