PHP Tutorial - PHP date_timestamp_set() Function






Definition

The date_timestamp_set() function sets the date and time based on a Unix timestamp.

Syntax

PHP date_timestamp_set() Function has the following syntax.

date_timestamp_set(object,unixtimestamp);

Parameter

ParameterIs RequiredDescription
objectRequired.DateTime object returned by date_create().
unixtimestampRequired.Unix timestamp representing the date

Return

PHP date_timestamp_set() Function returns the DateTime object. FALSE on failure.

Example

Set the date and time based on a Unix timestamp:


<?php
$date=date_create();

date_timestamp_set($date,1234500000);

echo date_format($date,"U = Y-m-d H:i:s");
?>

The code above generates the following result.