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

1 · time

<?

$time = "t";

$return = strtotime($time);

echo $return;

?>
1674934745

2 · now

<?

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

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

echo $return;

?>
1674934745

3 · 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");

?>
1674909545

1674909544
1674909485
1674905945
1674823145
1674304745
1672231145
1643373545
1646746806

1674909546
1674909605
1674913145
1674995945
1675514345
1677587945
1706445545
1709818806

1674432000
1675036800

946684800
32503680000

4 · 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 30th of January 2023 at 12:00:00 AM

checkdate

date

date_add

date_create

date_create_from_format

date_create_immutable

date_create_immutable_from_format

date_date_set

date_default_timezone_get

date_default_timezone_set

date_diff

date_format

date_get_last_errors

date_interval_create_from_date_string

date_interval_format

date_isodate_set

date_modify

date_offset_get

date_parse

date_parse_from_format

date_sub

date_sun_info

date_sunrise

date_sunset

date_time_set

date_timestamp_get

date_timestamp_set

date_timezone_get

date_timezone_set

getdate

gettimeofday

gmdate

gmmktime

gmstrftime

idate

localtime

microtime

mktime

strftime

strptime

time

timezone_abbreviations_list

timezone_identifiers_list

timezone_location_get

timezone_name_from_abbr

timezone_name_get

timezone_offset_get

timezone_open

timezone_transitions_get

timezone_version_get

PHP

Home Menu