Convert English textual date and time expressions 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”)); ?> |
The strtotime() function converts English textual date and time descriptions into Unix timestamps, which represent the number of seconds since January 1, 1970, 00:00:00 GMT.
Note on Two-Digit Years: When a two-digit year is provided, values from 0 to 69 are interpreted as 2000 to 2069, while values from 70 to 100 are interpreted as 1970 to 2000.
Note on Date Formats: For dates in the m/d/y or d-m-y formats, if a slash (/) is used as the separator, the function assumes the American m/d/y format. If a dash (-) or dot (.) is used, it assumes the European d-m-y format. To minimize errors, use the YYYY-MM-DD format or the date_create_from_format() function when possible.
strtotime(time, now); |
Parameter |
Description |
time |
Mandatory. Specifies a date/time string. |
now |
Optional. Specifies the timestamp that serves as the reference point for calculating relative dates. |
Return Value: |
Returns a timestamp on success or |
PHP Version: |
4+ |
PHP Changelog: |
PHP 5.3.0: Relative time formats like “this week,” “previous week,” “last week,” and “next week” now interpret a week as Monday through Sunday, rather than a 7-day period relative to the current date/time. PHP 5.3.0: The time format “24:00” is now valid. PHP 5.2.7: Previously, if a given weekday occurrence was requested in a month where that weekday was the first day, it would incorrectly add one week to the returned timestamp. This issue has been corrected. PHP 5.1.0: Now returns FALSE on failure (earlier versions returned -1) and issues E_STRICT and E_NOTICE time zone errors. PHP 5.0.2: Correctly computes “now” and other relative times from the current time, rather than from midnight of the current day. PHP 5.0.0: Allows microseconds in time formats, though they are ignored. |