PHP | DateTimeImmutable setDate() Function
Last Updated :
11 Oct, 2019
The DateTimeImmutable::setDate() function is an inbuilt function in PHP which is used to set a new date in the created DateTimeImmutable object.
Syntax:
DateTimeImmutable DateTimeImmutable::setDate( int $year, int $month, int $day )
Parameters: This function accepts three parameters as mentioned above and described below:
- $year: This parameter holds the year value in integer format.
- $month: This parameter holds the month value in integer format.
- $day: This parameter holds the date value in integer format.
Return Values: This function returns the new date object.
Below programs illustrate the DateTimeImmutable::setDate() function in PHP:
Program 1:
<?php
$datetimeImmutable = new DateTimeImmutable();
$Year = '2019' ;
$Month = '10' ;
$Day = '03' ;
$a = $datetimeImmutable ->setDate( $Year , $Month , $Day );
echo $a ->format( 'Y-m-d' );
?>
|
Program 2:
<?php
$datetimeImmutable = new DateTimeImmutable();
$a = $datetimeImmutable ->setDate(2019, 10, 03);
echo $a ->format( 'Y-m-d' );
?>
|
Reference: https://www.php.net/manual/en/datetimeimmutable.setdate.php
Share your thoughts in the comments
Please Login to comment...