PHP 5 >= 5.3.0, PHP 7, PHP 8
DateTime::getTimestamp - Gets the Unix timestamp
Code Examples

DateTime::getTimestamp( ): public int
public intDateTimeImmutable::getTimestamp


This function has no parameters.

Return Values

Returns the Unix timestamp representing the date.

Exceptions and Errors

If the timestamp cannot be represented as int, a ValueError is thrown. Prior to PHP 8.0.0, false was returned in this case. Still, the timestamp can be retrieved as string by using DateTimeInterface::format with the U format.


Version Description
8.0.0 These functions no longer return false on failure.

Related Functions

Example of DateTime::getTimestamp

Show all examples for DateTime::getTimestamp

PHP Version:

Function DateTime::getTimestamp:

Date and Time Functions

Most used PHP functions