PHP | date_timestamp_set() Function Last Updated : 17 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 oriented style: DateTime::setTimestamp( $unixtimestamp ) Parameters: This function accepts two 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. $unixtimestamp: This parameter is used to set the Unix timestamp representing the date. Return Value: This function returns the DateTime object on success or False on failure. Below programs illustrate the date_timestamp_set() function in PHP: Program 1: php <?php // Create DateTime object $date = date_create(); // Display DateTime in given format echo date_format($date, 'U = d-m-Y H:i:s') . "\n"; // date_timestamp_set function to Set // Unix timestamp date_timestamp_set($date, 1373502124); // Display DateTime in given format echo date_format($date, 'U = d-m-Y H:i:s'); ?> Output: 1537159667 = 17-09-2018 04:47:47 1373502124 = 11-07-2013 00:22:04 Program 2: php <?php // Create DateTime object $date = new DateTime(); // Display DateTime in given format echo $date->format('U = d-m-Y H:i:s') . "\n"; // date_timestamp_set function to Set // Unix timestamp $date->setTimestamp(1171564674); // Display DateTime in given format echo $date->format('U = d-m-Y H:i:s'); ?> Output: 1537159667 = 17-09-2018 04:47:47 1171564674 = 15-02-2007 18:37:54 Related Articles: PHP | date_default_timezone_set() Function PHP | date_get_last_errors() Function PHP | date_default_timezone_get() Function Reference: http://php.net/manual/en/datetime.settimestamp.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_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_timestamp_get() Function The date_timestamp_get() function is an inbuilt function in PHP which is used to gets the Unix timestamp. This function returns the Unix timestamp representing the date. Syntax: Procedural style: int date_timestamp_get( $object ) Object oriented style: int DateTime::getTimestamp( void ) int DateTime 1 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 | 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 | 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 Like