PHP strtotime() function

Example

Parse English text date and time into Unix timestamp:

<?php
echo(strtotime("now") . "<br>");
echo(strtotime("15 October 1980") . "<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"));
?>

Run Example

Definition and Usage

The strtotime() function parses any English text description of a date or time into a Unix timestamp (the number of seconds since January 1, 1970 00:00:00 GMT).

Note:If the year is represented using a two-digit format, the value 0-69 will map to 2000-2069, and the value 70-100 will map to 1970-2000.

Note:Please note the date format m/d/y or d-m-y. If the separator is a slash (/), use the American m/d/y format. If the separator is a hyphen (-) or a dot (.), use the European d-m-y format. To avoid potential errors, you should use the YYYY-MM-DD format or use the date_create_from_format() function as much as possible.

Syntax

strtotime(time,now);
Parameters Description
time Required. Specifies the date/time string.
now Optional. Specifies the timestamp to be used for the calculation of the return value. If this parameter is omitted, the current time is used.

Technical Details

Return Value: Returns a timestamp if successful, returns FALSE if failed.
PHP Version: 4+

Update Log:

5.3.0: Now relative time formats, such as this week, last week, the previous week, the next week, specify that a week starts from Monday to Sunday, not using the 7 days before and after the current date/time.
5.3.0 Before PHP 5.3.0, 24:00 was not a valid format, and strtotime() would return FALSE.
5.2.7 In previous versions, if a specific date in a month was requested and that date was the first day of the month, it would incorrectly add a week to the returned timestamp, which has now been corrected.
5.1.0 Returns FALSE if the operation fails (in previous versions it would return -1), and adds E_STRICT and E_NOTICE timezone errors.
5.0.2 Now the calculation of "now" and other relative time is based on the current time, not on the time of midnight today.
5.0.0 Microseconds are allowed (but the microsecond value is usually ignored).
4.4.0 Before PHP 4.4, "next" was incorrectly calculated as +2. The usual solution is to use "+1".