Skip to content
Tutorials Center
My learning

Topics

PHP Reference ยท Date and Time

PHP strtotime() function

Reference for PHP strtotime(): parse English date and time text such as '2025-03-01', 'next monday' or '+2 weeks' into a Unix timestamp, plus failure and time zone rules.

strtotime() reads a string that describes a date, a time or a relative moment, and returns the matching Unix timestamp. It understands ISO dates (2025-03-01), many common written forms (1 March 2025), and relative phrases such as tomorrow, next friday or +3 days.

Relative phrases are calculated from a base time, which is the current time unless you pass a second argument. Text without a time zone is read in the default time zone. When the text cannot be parsed, the function returns false, so always check the result.

PHP
<?php
$ts = strtotime("2025-03-01 12:00 UTC");
echo $ts;   // 1740830400

Try it

PHP Absolute and relative text

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

PHP Failure, ambiguity and time zones

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

Syntax

PHP
strtotime(string $datetime, ?int $baseTimestamp = null): int|false
Name Description
$datetime The text to parse. Absolute dates, times, time zones and relative parts can be combined.
$baseTimestamp Optional. The timestamp that relative phrases and missing fields are calculated from. Defaults to the current time.

Return value: a Unix timestamp (int), or false when the string is not understood. An empty string gives false.

Usage notes

  • Check for false. Treating false as 0 silently gives 1 January 1970. Use === false.
  • Ambiguous formats. 04/05/2025 is April 5 (US order); 04-05-2025 and 04.05.2025 are May 4 (day first). Prefer ISO YYYY-MM-DD, or use DateTimeImmutable::createFromFormat() when you know the exact layout.
  • Time of day. A date without a time means midnight. Relative words like tomorrow also reset the time to midnight, while +1 day keeps the time of day.
  • Weekday words. next friday is the first Friday after the base day; friday alone may be today if it is already a Friday; monday this week is the Monday of the current ISO week.
  • Month-end surprises. 2025-01-31 +1 month is 3 March, because February 31 rolls over. Use last day of next month for end-of-month logic.
  • Impossible dates roll over (2025-02-30 becomes March 2) without any error. Validate with checkdate() for user input, or use date_parse() to inspect warnings.
  • Do not trust it with user text. The parser is very forgiving and accepts strings you may not expect. Validate the format first.
  • Time zones in the string win over the default time zone. Daylight saving changes are handled for named zones.
  • English only. Month and day names must be English.