PHP.nl

strtotime

strtotime

Parse about any English textual datetime description into a Unix timestamp

 **strtotime** string $datetime  $baseTimestamp

The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in , or the current time if is not supplied. The date string parsing is defined in , and has several subtle considerations. Reviewing the full details there is strongly recommended. baseTimestamp``baseTimestampDate and Time Formats

Waarschuwing: > 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

Each parameter of this function uses the default time zone unless a time zone is specified in that parameter. Be careful not to use different time zones in each parameter unless that is intended. See on the various ways to define the default time zone. date_default_timezone_get

datetimedate.formats.parameter

baseTimestampThe timestamp which is used as a base for the calculation of relative dates.

Returns a timestamp on success, false otherwise.

Voorbeeld: A example

<?php
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";

Voorbeeld: Checking for failure

<?php
$str = 'Not Good';

if (($timestamp = strtotime($str)) === false) {
    echo "The string ($str) is bogus";
} else {
    echo "$str == " . date('l dS \o\f F Y h:i:s A', $timestamp);
}

Opmerking: > "Relative" date in this case also means that if a particular component of the date/time stamp is not provided, it will be taken verbatim from the . That is, , if run on the 31st of May 2022, will be interpreted as , which will overflow into a timestamp on . (In a leap year, it would be .) Using or would avoid that problem. baseTimestamp``strtotime('February')``31 February 2022``3 March``2 March``strtotime('1 February')``strtotime('first day of February')

Opmerking: > If the number of the year is specified in a two digit format, the values between 00-69 are mapped to 2000-2069 and 70-99 to 1970-1999. See the notes below for possible differences on 32bit systems (possible dates might end on 2038-01-19 03:14:07).

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

For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 billion years in either direction.

Opmerking: > Using this function for mathematical operations is not advisable. It is better to use and . DateTime::add``DateTime::sub

DateTimeImmutable``DateTimeImmutable::createFromFormatDate and Time Formatscheckdate``strptime