- 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)
- $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.
// 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