HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

strtotime

Description

The strtotime of Date / Time for PHP parse about any English textual datetime description into a Unix timestamp.

Syntax

strtotime(
    string $datetime,
    ?int $baseTimestamp = null
): int|false

Parameters

time

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

baseTimestamp

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

Return

Returns a timestamp on success, false otherwise.

Examples

1 · datetime

<?

$datetime = "now";

$return = strtotime($datetime);

echo $return;
1776302190

2 · baseTimestamp

<?

$datetime = "now";
$baseTimestamp = time();

$return = strtotime($datetime, $baseTimestamp);

echo $return;
1776302190

3 · -

<?

$array =
[
    "now",
    "-1 second",
    "-1 minute",
    "-1 hour",
    "-1 day",
    "-1 week",
    "-1 month",
    "-1 year",
    "-1 year -1 month -1 week -1 day -1 hour -1 minute -1 second"
];

foreach($array as $datetime)
{
    $return = strtotime($datetime);

    $format = "Y-m-d W H:i:s";

    $date = date($format, $return);

    echo "$return: $date: $datetime\n";
}
1776302190: 2026-04-16 16 01:16:30: now
1776302189: 2026-04-16 16 01:16:29: -1 second
1776302130: 2026-04-16 16 01:15:30: -1 minute
1776298590: 2026-04-16 16 00:16:30: -1 hour
1776215790: 2026-04-15 16 01:16:30: -1 day
1775697390: 2026-04-09 15 01:16:30: -1 week
1773623790: 2026-03-16 12 01:16:30: -1 month
1744766190: 2025-04-16 16 01:16:30: -1 year
1741392929: 2025-03-08 10 00:15:29: -1 year -1 month -1 week -1 day -1 hour -1 minute -1 second

4 · +

<?

$array =
[
    "now",
    "1 second",
    "1 minute",
    "1 hour",
    "1 day",
    "1 week",
    "1 month",
    "1 year",
    "1 year 1 month 1 week 1 day 1 hour 1 minute 1 second"
];

foreach($array as $datetime)
{
    $return = strtotime($datetime);

    $format = "Y-m-d W H:i:s";

    $date = date($format, $return);

    echo "$return: $date: $datetime\n";
}
1776302191: 2026-04-16 16 01:16:31: now
1776302192: 2026-04-16 16 01:16:32: 1 second
1776302251: 2026-04-16 16 01:17:31: 1 minute
1776305791: 2026-04-16 16 02:16:31: 1 hour
1776388591: 2026-04-17 16 01:16:31: 1 day
1776906991: 2026-04-23 17 01:16:31: 1 week
1778894191: 2026-05-16 20 01:16:31: 1 month
1807838191: 2027-04-16 15 01:16:31: 1 year
1811125052: 2027-05-24 21 02:17:32: 1 year 1 month 1 week 1 day 1 hour 1 minute 1 second

5 · day-based

<?

$array =
[
    "now",
    "yesterday",
    "today",
    "midnight",
    "noon",
    "tomorrow",
    "front of 12",
    "back of 12",
    "previous day",
    "next day",
    "1 day ago",
    "-1 day ago",
    "first day of",
    "last day of"
];

foreach($array as $datetime)
{
    $return = strtotime($datetime);

    $format = "Y-m-d W H:i:s";

    $date = date($format, $return);

    echo "$return: $date: $datetime\n";
}
1776302191: 2026-04-16 16 01:16:31: now
1776211200: 2026-04-15 16 00:00:00: yesterday
1776297600: 2026-04-16 16 00:00:00: today
1776297600: 2026-04-16 16 00:00:00: midnight
1776340800: 2026-04-16 16 12:00:00: noon
1776384000: 2026-04-17 16 00:00:00: tomorrow
1776339900: 2026-04-16 16 11:45:00: front of 12
1776341700: 2026-04-16 16 12:15:00: back of 12
1776215791: 2026-04-15 16 01:16:31: previous day
1776388591: 2026-04-17 16 01:16:31: next day
1776215791: 2026-04-15 16 01:16:31: 1 day ago
1776388591: 2026-04-17 16 01:16:31: -1 day ago
1775006191: 2026-04-01 14 01:16:31: first day of
1777511791: 2026-04-30 18 01:16:31: last day of

6 · specific

<?

$array =
[
    "01-02-03",
    "3 february 2001"
];

foreach($array as $datetime)
{
    $return = strtotime($datetime);

    $format = "Y-m-d W H:i:s";

    $date = date($format, $return);

    echo "$return: $date: $datetime\n";
}
981158400: 2001-02-03 05 00:00:00: 01-02-03
981158400: 2001-02-03 05 00:00:00: 3 february 2001

7 · holidays

<?

$array =
[
    "Mother's Day" => "second sunday of may",
    "Memorial Day" => "last monday of may",
    "Father's Day" => "third sunday of june",
    "Thanksgiving Day" => "fourth thursday of november"
];

foreach($array as $key => $datetime)
{
    $return = strtotime($datetime);

    $format = "Y-m-d";

    $date = date($format, $return);

    echo "$date: $key\n";
}
2026-05-10: Mother's Day
2026-05-25: Memorial Day
2026-06-21: Father's Day
2026-11-26: Thanksgiving Day

8 · escape

<?

$datetime = "next day";

$return = strtotime($datetime);

$format = 'l \t\h\e jS \o\f F Y \a\t h:i:s A';

$date = date($format, $return);

echo "\"$datetime\" is $date";
"next day" is Friday the 17th of April 2026 at 01:16:31 AM