PHP strtotime() Function
Example
Parse English textual datetimes into Unix timestamps:
<?php
echo(strtotime("now") . "<br>");
echo(strtotime("3 October 2005") . "<br>");
echo(strtotime("+5 hours") . "<br>");
echo(strtotime("+1 week") . "<br>");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>");
echo(strtotime("next Monday") . "<br>");
echo(strtotime("last Sunday"));
?>
Try it Yourself »
Definition and Usage
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).
Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
Note: Be aware of dates in the m/d/y or d-m-y formats; if the separator is a slash (/), then the American m/d/y is assumed. If the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. To avoid potential errors, you should YYYY-MM-DD dates or date_create_from_format() when possible.
Syntax
strtotime(datetime_string, basetimestamp);
Parameter Values
| Parameter | Description |
|---|---|
| datetime_string | Required. Specifies a date/time string |
| basetimestamp | Optional. Specifies the timestamp used as a base for the calculation of relative dates |
Technical Details
| Return Value: | Returns a timestamp on success. FALSE on failure |
|---|---|
| PHP Version: | 4+ |
| PHP Changelog: | PHP 8.0: basetimestamp is nullable now |
❮ PHP Date/Time Reference