PHP | DateTimeImmutable setDate() Function Last Updated : 11 Oct, 2019 Summarize Comments Improve Suggest changes Share 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 Comment More infoAdvertise with us Next Article PHP | DateTime setDate() Function K Kanchan_Ray Follow Improve Article Tags : Web Technologies PHP PHP-date-time PHP-function Similar Reads PHP | DateTimeImmutable setISODate() Function The DateTimeImmutable::setISODate() function is an inbuilt function in PHP which is used to sets the ISO (International Organization for Standardization ) date into the created DateTimeImmutable object. This function sets the date according to the ISO 8601 standard, using weeks and day offsets rathe 2 min read PHP | DateTimeImmutable::setTimezone() Function The DateTimeImmutable::setTimezone() function is an inbuilt function in PHP which is used to set the time zone for the created DateTimeImmutable object. This function returns the DateTimeImmutable object or False on failure. Syntax: DateTimeImmutable::setTimezone ( TimeZone ) Parameters: This functi 1 min read PHP | DateTimeImmutable setTimestamp() Function The DateTimeImmutable::setTimestamp() function is an inbuilt function in PHP which is used to set the date and time based on an Unix timestamp. Syntax: DateTimeImmutable DateTimeImmutable::setTimestamp( int $unixtimestamp ) Parameters: This function accepts single parameter $unixtimestamp which is u 1 min read PHP | DateTimeImmutable::sub() Function The DateTimeImmutable::sub() function is an inbuilt function in PHP which is used to subtract a number of days, months, years, hours, minutes and seconds from a created DateTimeImmutable object. Syntax: DateTimeImmutable::sub( interval ) Parameters: This function accepts a parameter interval which i 2 min read PHP | DateTime setDate() Function The DateTime::setDate() function is an inbuilt function in PHP which is used to reset the current date of DateTime object with the given date-time object. Syntax: Object oriented style: DateTime DateTime::setDate( int $year, int $month, int $day ) Procedural style: DateTime date_date_set( DateTime $ 2 min read PHP | DateTimeImmutable add() Function The DateTimeImmutable::add() function is an inbuilt function in PHP which is used to add a number of days, months, years, hours, minutes and seconds to a created DateTimeImmutable object. Syntax: DateTimeImmutable DateTimeImmutable::add( DateInterval $interval ) Parameters: This function accepts a s 2 min read Like