strtotime()
strtotime() — Parse about any English textual datetime description into a Unix timestamp.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
The Unix timestamp that this function returns does not contain information about time zones. In order to do calculations with date/time information, you should use the more capable DateTimeImmutable.
Signature
strtotime(string $datetime, ?int $baseTimestamp = null): int|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $datetime | string | A date/time string. Valid formats are explained in Date and Time Formats. |
| $baseTimestamp | ?int | The timestamp which is used as a base for the calculation of relative dates. |
Return value
Returns a timestamp on success, false otherwise.
Example
A runnable snippet:
echo strtotime("now"), "\n"; echo strtotime("10 September 2000"), "\n"; echo strtotime("+1 day"), "\n"; echo strtotime("+1 week"), "\n"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n"; echo strtotime("next Thursday"), "\n"; echo strtotime("last Monday"), "\n";
Changelog
| Version | Change |
|---|---|
| 8.0.0 | baseTimestamp is nullable now. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page strtotime() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.