HomeLanguagesPHP | DateTimeImmutable setISODate() Function

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:




<?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

RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS