PHP | DateTimeImmutable setISODate() Function
Last Updated :
11 Oct, 2019
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
$datetimeImmutable = new DateTimeImmutable();
$Year = '2019' ;
$Week = '10' ;
$Day = '03' ;
$a = $datetimeImmutable ->setISODate( $Year , $Week , $Day );
echo $a ->format( 'Y-m-d' );
?>
|
Output:
2019-03-06
Program 2:
<?php
$datetimeImmutable = new DateTimeImmutable();
$a = $datetimeImmutable ->setISODate(2019, 9, 03);
echo $a ->format( 'Y-m-d' );
?>
|
Output:
2019-02-27
Reference: https://www.php.net/manual/en/datetimeimmutable.setisodate.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...