time
Returns the current timestamp.
Syntax
time(): intReturn value
intThe number of seconds since 1 January 1970.
Examples
A timestamp is a large integer:
<?php
echo time();The time in an hour and in a week:
<?php
$now = mktime(12, 0, 0, 1, 30, 2025);
echo date('H:i', $now + 3600), "\n";
echo date('d.m.Y', $now + 7 * 24 * 3600);Output:
13:00
06.02.2025Notes
Timestamps are easy to compare and store. For complex date arithmetic DateTimeImmutable objects are more reliable.
See also
Related recipes
In the tutorial
- Date and time — Working with dates in PHP — the date function, the DateTimeImmutable class, formats, adding to dates and the difference between them.