Home/Guides/PHP strtotime Examples

PHP Date Guides

PHP strtotime Examples

Common PHP strtotime examples for relative dates, fixed dates, and date formatting.

PHP strtotime() parses English-like date strings into Unix timestamps.

Code examples

echo date('Y-m-d', strtotime('+1 week'));
echo date('Y-m-d', strtotime('next Monday'));

Check for failure:

$timestamp = strtotime($input);

if ($timestamp === false) {
    throw new InvalidArgumentException('Invalid date');
}

Common errors

Relative phrases depend on the current time and timezone. For critical logic, prefer DateTimeImmutable with explicit timezones.

Try the PHP strtotime Tester.

FAQ

What does strtotime return?

It returns a Unix timestamp or false on failure.

Should I check for false?

Yes. Always handle parse failures explicitly.

Related tools

Related guides