strtotime
Turns a textual date description into a timestamp.
Syntax
strtotime(string $datetime, ?int $baseTimestamp = null): int|falseParameters
| Parameter | Type | Description |
|---|---|---|
| $datetime | string | A date as a string: `2025-01-30`, `+1 week`, `tomorrow`. |
| $baseTimestamp | ?int | Optional. 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.2025Relative 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.2025Notes
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
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.