Home Menu

strtotime

Parse about any English textual datetime description into a Unix timestamp

Syntax

strtotime ( string $time [, int $now = time() ] ) : int

Parameters

time

A date/time string. Valid formats are explained in Date and Time Formats.

now

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

Return

Returns a timestamp on success, FALSE otherwise.

Examples

time

<?

$time = "t";

$return = strtotime($time);

echo $return;

?>
1627118660

now

<?

$time = "t";
$now = time();

$return = strtotime($time, $now);

echo $return;

?>
1627118660

1

<?

echo strtotime("now") . PHP_EOL . PHP_EOL;

echo strtotime("-1 second") . PHP_EOL;
echo strtotime("-1 minute") . PHP_EOL;
echo strtotime("-1 hour") . PHP_EOL;
echo strtotime("-1 day") . PHP_EOL;
echo strtotime("-1 week") . PHP_EOL;
echo strtotime("-1 month") . PHP_EOL;
echo strtotime("-1 year") . PHP_EOL;
echo strtotime("-1 year 1 month 1 week 1 day 1 hour 1 minute 1 second") . PHP_EOL . PHP_EOL;

echo strtotime("1 second") . PHP_EOL;
echo strtotime("1 minute") . PHP_EOL;
echo strtotime("1 hour") . PHP_EOL;
echo strtotime("1 day") . PHP_EOL;
echo strtotime("1 week") . PHP_EOL;
echo strtotime("1 month") . PHP_EOL;
echo strtotime("1 year") . PHP_EOL;
echo strtotime("1 year 1 month 1 week 1 day 1 hour 1 minute 1 second") . PHP_EOL . PHP_EOL;

echo strtotime("last monday") . PHP_EOL;
echo strtotime("next monday") . PHP_EOL . PHP_EOL;

echo strtotime("1 january 2000") . PHP_EOL;
echo strtotime("1 january 3000");

?>
1627093460

1627093459
1627093400
1627089860
1627007060
1626488660
1624501460
1595557460
1598930721

1627093461
1627093520
1627097060
1627179860
1627698260
1629771860
1658629460
1662002721

1626652800
1627257600

946684800
32503680000

2

<?

$string = "next monday";
$timestamp = strtotime($string);

if ($timestamp === false) {
    echo "\"$string\" is invalid";
} else {
    echo "\"$string\" is " . date('l \t\h\e jS \o\f F Y \a\t h:i:s A', $timestamp);
}

?>
"next monday" is Monday the 26th of July 2021 at 12:00:00 AM

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms