PHP Manual
Prev |  | Next

# strtotime

(PHP 3>= 3.0.12, PHP 4 )

strtotime -- Parse about any English textual datetime description into a UNIX timestamp

## Description

int strtotime ( string time [, int now])

The function expects to be given a string containing an English date format and will try to parse that format into a UNIX timestamp relative to the timestamp given in `now`, or the current time if none is supplied. Upon failure, `-1` is returned.

Because strtotime() behaves according to GNU date syntax, have a look at the GNU manual page titled Date Input Formats. Described there is valid syntax for the `time` parameter.

Example 1. strtotime() examples
    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";

Example 2. Checking for failure
    $str = 'Not Good';
    if (($timestamp = strtotime($str)) === -1) {
        echo "The string ($str) is bogus";
    } else {
        echo "$str == ". date('l dS of F Y h:i:s A',$timestamp);
    }

> Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)

Prev | Home | Next
strftime | Up | time