PHP | date_time_set() Function Last Updated : 17 Sep, 2018 Comments Improve Suggest changes Like Article Like Report 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::setTime( $hour, $minute, $second, $microseconds ) Parameters: This function accepts five parameters as mentioned above and described below: $object: It is a mandatory parameter which is used to specify the DateTime object which is returned by the date_create() function. $hour: This parameter is used to set hour of time. $minute: This parameter is used to set minute of time. $second: This parameter is used to set second of time. $microsecond: This parameter is used to set microsecond of time. Return Value: This function returns the DateTime object on success or False on failure. Below programs illustrate the date_time_set() function in PHP: Program 1: php <?php // Create an DateTime object $date = date_create('2018-09-15'); // Set the new DateTime date_time_set($date, 8, 30); // Display the date in given format echo date_format($date, 'd-m-Y H:i:s') . "\n"; // Set the new DateTime date_time_set($date, 12, 40, 30); // Display the date in given format echo date_format($date, 'Y-m-d H:i:s') . "\n"; ?> Output: 15-09-2018 08:30:00 2018-09-15 12:40:30 Program 2: php <?php // Create DateTime object $date = new DateTime('2018-09-15'); // Set the new DateTime $date->setTime(12, 30); // Display the date in given format echo $date->format('d-m-Y H:i:s') . "\n"; // Set the new DateTime $date->setTime(12, 30, 20); // Display the date in given format echo $date->format('Y-m-d H:i:s'); ?> Output: 15-09-2018 12:30:00 2018-09-15 12:30:20 Related Articles: PHP | timezone_open() Function PHP | timezone_abbreviations_list() Function PHP | timezone_location_get() Function Reference: http://php.net/manual/en/datetime.settime.php Comment More infoAdvertise with us Next Article PHP | date_time_set() Function V vijay_raj Follow Improve Article Tags : Misc Web Technologies PHP PHP-date-time PHP-function +1 More Practice Tags : Misc Similar Reads 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 | 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 | 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 | date_sunrise() Function The date_sunrise() is an inbuilt function in PHP which is used to find the sunrise time for a specified day and location. This function returns the time of the sunrise, in the specified format, on success. FALSE on failure. Syntax: date_sunrise ( $timestamp, $format, $latitude, $longitude, $zenith, 2 min read Like