PHP | DateTimeImmutable setISODate() Function

The DateTimeImmutable::setISODate() function is an inbuilt function in PHP which is used to sets the ISO (International Organization for Standardization ) date into the created DateTimeImmutable object. This function sets the date according to the ISO 8601 standard, using weeks and day offsets rather than specific dates.

Syntax:

DateTimeImmutable DateTimeImmutable::setISODate( int year, int week, int day) )

Parameters: This function accepts three parameters as mentioned above and described below:



  • year: This parameter holds the year value in integer format.
  • week: This parameter holds the week value in integer format .
  • day: This parameter holds the day value in integer format ..

Return Values: This function returns a new date.

Below programs illustrate the DateTimeImmutable::setISODate() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to illustrate DateTimeImmutable::setISODate()
// function
    
// Creating a new DateTimeImmutable() object
$datetimeImmutable = new DateTimeImmutable();
  
// Initialising year, week and day
$Year = '2019';
$Week = '10';
$Day = '03';
  
// Calling the DateTimeImmutable::setISODate() function
$a = $datetimeImmutable->setISODate($Year, $Week, $Day);
  
// Getting a new set of date in the
// format of 'Y-m-d'
echo $a->format('Y-m-d');
?>

chevron_right


Output:

2019-03-06

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to illustrate DateTimeImmutable::setISODate()
// function
    
// Creating a new DateTimeImmutable() object
$datetimeImmutable = new DateTimeImmutable();
  
// Calling the setISODate() function
// with parameters like years of 2019,
// week of 9 and day of 3
$a = $datetimeImmutable->setISODate(2019, 9, 03);
  
// Getting a new set of date in the
// format of 'Y-m-d'
echo $a->format('Y-m-d');
?>

chevron_right


Output:

2019-02-27

Reference: https://www.php.net/manual/en/datetimeimmutable.setisodate.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.