Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

strtotime

Turns a textual date description into a timestamp.

Syntax

strtotime(string $datetime, ?int $baseTimestamp = null): int|false

Parameters

ParameterTypeDescription
$datetimestringA date as a string: `2025-01-30`, `+1 week`, `tomorrow`.
$baseTimestamp?intOptional. The moment relative dates are counted from.

Return value

int|falseA timestamp, or `false` if the string could not be parsed.

Examples

A date from a string:

<?php
 
echo date('d.m.Y', strtotime('2025-01-30'));

Output:

30.01.2025

Relative dates:

<?php
 
$base = strtotime('2025-01-30');
 
echo date('d.m.Y', strtotime('+1 week', $base)), "\n";
echo date('d.m.Y', strtotime('first day of next month', $base));

Output:

06.02.2025
01.02.2025

Notes

The function understands 30.01.2025, but treats 30/01/2025 as the American "month/day" form and returns false. For user input DateTimeImmutable::createFromFormat() is more reliable.

See also

  • date — Formats a date and time.
  • time — Returns the current timestamp.

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.

Thanks for reading!

Donate to the site — we work hard for you.