Open In App

PHP | DateTimeImmutable setISODate() Function

Last Updated : 11 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:




<?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');
?>


Output:

2019-03-06

Program 2:




<?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');
?>


Output:

2019-02-27

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads