What date formats does PHP strtotime () support?

I really like the PHP function strtotime (), but the user manual does not give a complete description of the supported date formats. He gives only a few examples, such as September 10, 2000, +1 Week 2 Days 4 Hours 2 Seconds, and Next Thursday.

Where can I find a full description?

+4
source share
4 answers

I cannot find anything official, but I saw a tutorial that says strtotime () uses GNU data input formats. These are described in detail in the GNU manual .

One mismatch that I notice is that the β€œnext” is not as described in the GNU manual. Using strtotime (), "next Thursday" will give you the same result as "Thursday" if today is not Thursday.

If today is Thursday, then

  • strtotime ("Thursday") == strtotime ("today")
  • strtotime ("next Thursday") == strtotime ("today + 7 days")

If today is not Thursday, then

  • strtotime ("Thursday") == strtotime ("next Thursday")

I am using PHP 5.2.6.

Update:

I think the user guide has been updated since I posted this, otherwise I was blind. It now contains a link to the "Date and Time Formats" section , which includes the relative formats section.

+7
source

You can start tracking what it does by looking at the following C code:

http://cvs.php.net/viewvc.cgi/php-src/ext/date/php_date.c

Search for PHP_FUNCTION (strtotime)

This is also the main regular expression parsing:

http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/parse_date.re

Good luck.

+1
source

In my experience, strtotime () can accept anything even remotely like a date. The best way to find out its boundaries is to create a test script and plug in the values ​​and see what it does and doesn't work.

$input = "Apr 10th"; print(date('Ym-d', strtotime($input))); 

Just keep changing the $ input variable and watch the results.

0
source

Basically, everything that date can create strtotime will be parsed. With one exception, he has issues with non-American-style formatting. Therefore, save the format of the month in the format "Day-Year-Year".

0
source

All Articles