Change language

PHP DateTime setDate () function

Syntax:
  • Object Oriented Style:
    DateTime DateTime::setDate (int  $year, int $month, int $day)
  • Procedural style:
    DateTime  date_date_set (DateTime $object, int $year, int $month, int $day) 
Parameters:This function takes three parameters as above and described below:
  • $year:this parameter contains the value of the year of the date.
  • $month:this parameter contains the value of the month of the date.
  • $day: this parameter contains the value of the day of the date.
Return Value:This function returns a new DateTime object on success, or False on error.The following programs illustrate the DateTime::setDate() function in PHP:Program 1 :
// PHP illustration program
// DateTime::setDate() function 
// Create a new DateTime() $datetime = new DateTime();  
// Initialize year, month and day $Year = ’2019’ ; $Month = ’09’ ; $Day = ’30’ ;  
// Calling the setDate() function $datetime -> setDate ( $Year , $Month , $Day );  
// Get a new set of dates in // format ’ Ymd ’ echo $datetime -> format ( ’ Ymd’ ); ?>
Exit:
2019-09 -30
Program 2:
// PHP illustration program
// DateTime::setDate() function 
// Create a new DateTime() object $datetime = new DateTime();  
// Calling the setDate() function // with parameters such as 2019
// month 10 and day 1 $datetime -> setDate (2019, 10, 01);  
// Get a new set of dates in // format ’ Ymd ’ echo $datetime -> format ( ’ Ymd’ ); ?>
Exit:
2019-10 -01
Link: https://www.php. net / manual / en / datetime.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