time
Returns the current time as the number of seconds since the Unix epoch.
time(): int- Added in PHP 4.0
Return value
intThe current Unix timestamp: whole seconds elapsed since 1 January 1970 00:00:00 UTC.
time() is the simplest function in the date extension: no arguments, no failure mode, just the current second count since the epoch. That integer is time-zone independent — the same instant produces the same number everywhere on Earth. A time zone only enters the picture when you format it with date().
When to reach for it
Use it to stamp records, to compute expiries ($expires = time() + 3600), and to compare stored timestamps. Integer arithmetic in seconds is exact and cheap, so "is this session older than 30 minutes" is just time() - $created > 1800.
What trips people up
Every call re-reads the clock. Two calls a few milliseconds apart can straddle a second boundary, so code that calls time() twice and expects the same value occasionally fails in a way that is nearly impossible to reproduce. Capture it once into a variable, or use $_SERVER['REQUEST_TIME'], which stays fixed for the whole request.
Also resist doing calendar arithmetic in raw seconds. time() + 30 * 86400 is not "one month" and not even reliably 30 days, because a daylight-saving transition makes some days 23 or 25 hours long. For anything involving days, months or years, use strtotime('+1 month') or DateTimeImmutable::modify(), which understand the calendar.
Example
When to use it
- Store a created_at or updated_at value as an integer column
- Check whether a cached file or session token has expired
- Compute the age of a record in days from a stored timestamp
Frequently asked questions
What time zone does time() use?
None. A Unix timestamp is an absolute count of seconds since the epoch in UTC; the time zone only affects how date() renders it.
What is the difference between time and microtime?
time returns whole seconds as an int, microtime returns the same instant with microsecond precision. Use microtime(true) when you need sub-second resolution.
How do I get the timestamp of when the request started?
Read $_SERVER['REQUEST_TIME'] (or REQUEST_TIME_FLOAT for microseconds). Unlike time(), it stays constant for the whole request.
More examples
Expiry check on a stored timestamp
Capturing $now once means both rows are judged against the same instant. The output shows 120s valid and 5400s expired against a 30-minute (1800 second) window.
<?php
date_default_timezone_set('UTC');
$now = time();
$sessions = [
'fresh' => $now - 120,
'stale' => $now - 5400,
];
foreach ($sessions as $name => $created) {
$age = $now - $created;
$state = $age > 1800 ? 'expired' : 'valid';
echo "$name: {$age}s old, $state\n";
}Why raw second arithmetic drifts
Adding 86400 seconds across the British DST switch lands at 13:00 rather than 12:00, while '+1 day' keeps the wall-clock time. This is why day and month arithmetic belongs in strtotime or DateTimeImmutable, not in raw seconds.
<?php
date_default_timezone_set('Europe/London');
$start = strtotime('2025-03-29 12:00:00'); // day before the DST switch
echo 'naive +86400: ', date('Y-m-d H:i', $start + 86400), "\n";
echo 'calendar +1 day: ', date('Y-m-d H:i', strtotime('+1 day', $start)), "\n";
$in30 = new DateTimeImmutable('@' . $start);
echo 'plus one month: ', $in30->modify('+1 month')->format('Y-m-d'), "\n";
Discussion