PHP | DateTime setDate() Function Last Updated : 10 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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 $object, int $year, int $month, int $day ) Parameters: This function accepts three parameters as mentioned above and described below: $year: This parameter holds the value of year of the date. $month: This parameter holds the value of month of the date. $day: This parameter holds the value of day of the date. Return Value: This function returns a new DateTime object on success or False on failure. Below programs illustrate the DateTime::setDate() function in PHP: Program 1 : php <?php // PHP program to illustrate // DateTime::setDate() function // Creating a new DateTime() object $datetime = new DateTime(); // Initialising year, month and day $Year = '2019'; $Month = '09'; $Day = '30'; // Calling the setDate() function $datetime->setDate($Year, $Month, $Day); // Getting a new set of date in the // format of 'Y-m-d' echo $datetime->format('Y-m-d'); ?> Output: 2019-09-30 Program 2: php <?php // PHP program to illustrate // DateTime::setDate() function // Creating a new DateTime() object $datetime = new DateTime(); // Calling the setDate() function // with parameters like years of 2019, // month of 10 and day of 1 $datetime->setDate(2019, 10, 01); // Getting a new set of date in the // format of 'Y-m-d' echo $datetime->format('Y-m-d'); ?> Output: 2019-10-01 Reference: https://www.php.net/manual/en/datetime.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 setDate() Function 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 abo 2 min read PHP | DateTime sub() Function The DateTime::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 DateTime object. Syntax: Object oriented style: DateTime DateTime::sub( DateInterval interval ) Procedural style: DateTime date_sub( DateTim 2 min read PHP | date_time_set() Function The date_time_set() function is an inbuilt function in PHP which is used to sets the time. This function resets the current time of the DateTime object to a different time. Syntax: Procedural style: date_time_set( $object, $hour, $minute, $second, $microseconds ) Object oriented style: DateTime::set 2 min read PHP | date_date_set() Function The date_date_set() function is an inbuilt function in PHP which is used to set a new Date. This function has four parameters $object, $year, $month and $day and returns DateTime object on success or false on failure. The date_date_set() function is an alias of DateTime::setDate() function. Syntax: 2 min read 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 | date_sunset() Function The date_sunset() is an inbuilt function in PHP which is used to find the sunset time for a specified day and location. Syntax: date_sunset ( $timestamp, $format, $latitude, $longitude, $zenith, $gmtoffset ) Parameters: This function accepts four parameters as mentioned above and described below. $t 2 min read PHP | DateTime add() Function The DateTime::add() function is an inbuilt function in PHP which is used to add an amount of time (days, months, years, hours, minutes and seconds) to the given DateTime object. Syntax: Object oriented style: DateTime DateTime::add( DateInterval $interval ) Procedural style: DateTime date_add( DateT 2 min read PHP | date_timezone_set() Function The date_timezone_set() function is an inbuilt function in PHP which is used to sets the time zone for the DateTime object. This function returns the DateTime object or False on failure. Syntax: Procedural style: date_timezone_set( $object, $timezone ) Object oriented style: DateTime::setTimezone( $ 2 min read PHP | date_timestamp_set() Function The date_timestamp_set() function is an inbuilt function in PHP which is used to sets the date and time based on an Unix timestamp. This function returns the DateTime object for method chaining or False on failure. Syntax: Procedural style: date_timestamp_set( $object, $unixtimestamp ) Object orient 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 Like