Change language

PHP DateTimeImmutable setDate () function

Syntax:
DateTimeImmutable DateTimeImmutable::setDate (int $year, int  $month, int $day)
Parameters:This function takes three parameters as above and described below:
  • $year:this parameter contains an integer year value.
  • $month:this parameter contains an integer month value.
  • $day:this parameter contains the date value in integer format.
Return values:this function returns a new date object.The following programs illustrate the DateTimeImmutable::setDate()function in PHP:Program 1:  
// PHP illustration program DateTimeImmutable::setDate()
// function 
// Create a new DateTimeImmutable() $datetimeImmutable = new DateTimeImmutable();  
// Initialize year, month and day $Year = ’2019’ ; $Month = ’10’ ; $Day = ’03’ ;  
// Calling the DateTimeImmutable::setDate() function $a = $datetimeImmutable -> setDate ( $Year , $Month , $Day );  
// Get a new set of dates in // format ’ Ymd ’ echo $a -> format ( ’ Ymd’ ); ?>
Exit:
2019-10 -03
Program 2:  
// PHP illustration program DateTimeImmutable::setDate()
// function 
// Create a new object DateTimeImmutable() $datetimeImmutable = new DateTimeImmutable();  
// Calling the setDate() function // with parameters such as 2019
// month 10 and day 3 $a = $datetimeImmutable -> setDate (2019, 10, 03);  
// Get a new set of dates in // format ’ Ymd ’ echo $a -> format ( ’ Ymd’ ); ?>
Exit:
2019-10 -03
Link: https://www.php.net/manual/en/datetimeimmutable.setdate.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method