Example 1 — Get the Timestamp of a Date
Create dates in UTC and read their timestamps.
<?php
$utc = timezone_open("UTC");
$a = date_create("2024-01-01 00:00:00", $utc);
$b = date_create("2000-01-01 00:00:00", $utc);
$c = date_create("1970-01-01 00:00:00", $utc);
echo date_timestamp_get($a), PHP_EOL;
echo date_timestamp_get($b), PHP_EOL;
echo date_timestamp_get($c), PHP_EOL; How It Works
- Create a UTC timezone so the numbers are the same everywhere.
- Each date is built with date_create() using that timezone.
- date_timestamp_get() counts the seconds since January 1, 1970.
- The date 1970-01-01 00:00:00 UTC is the starting point, so its timestamp is 0.

