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 $ts = strtotime("2025-03-01 12:00 UTC"); echo $ts; // 1740830400
Try it
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.
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
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. Treatingfalseas0silently gives 1 January 1970. Use=== false. - Ambiguous formats.
04/05/2025is April 5 (US order);04-05-2025and04.05.2025are May 4 (day first). Prefer ISOYYYY-MM-DD, or useDateTimeImmutable::createFromFormat()when you know the exact layout. - Time of day. A date without a time means midnight. Relative words like
tomorrowalso reset the time to midnight, while+1 daykeeps the time of day. - Weekday words.
next fridayis the first Friday after the base day;fridayalone may be today if it is already a Friday;monday this weekis the Monday of the current ISO week. - Month-end surprises.
2025-01-31 +1 monthis 3 March, because February 31 rolls over. Uselast day of next monthfor end-of-month logic. - Impossible dates roll over (
2025-02-30becomes March 2) without any error. Validate withcheckdate()for user input, or usedate_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.
Related
date(),mktime(),checkdate(),date_parse(),DateTimeImmutable- Lessons: Dates and Times