PHP | DateTimeImmutable setDate() Function Last Updated : 11 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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 <?php // PHP program to illustrate DateTimeImmutable::setDate() // function // Creating a new DateTimeImmutable() object $datetimeImmutable = new DateTimeImmutable(); // Initialising year, month and day $Year = '2019'; $Month = '10'; $Day = '03'; // Calling the DateTimeImmutable::setDate() function $a = $datetimeImmutable->setDate($Year, $Month, $Day); // Getting a new set of date in the // format of 'Y-m-d' echo $a->format('Y-m-d'); ?> Output: 2019-10-03 Program 2: php <?php // PHP program to illustrate DateTimeImmutable::setDate() // function // Creating a new DateTimeImmutable() object $datetimeImmutable = new DateTimeImmutable(); // Calling the setDate() function // with parameters like years of 2019, // month of 10 and day of 3 $a = $datetimeImmutable->setDate(2019, 10, 03); // Getting a new set of date in the // format of 'Y-m-d' echo $a->format('Y-m-d'); ?> Output: 2019-10-03 Reference: https://www.php.net/manual/en/datetimeimmutable.setdate.php Create Quiz Comment K Kanchan_Ray Follow 0 Improve K Kanchan_Ray Follow 0 Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like