note 60545 rejected from function.strtotime by nlopess
| From: | nlopess@php.net | Date: | Tue, 10 Jan 2006 20:06:58 +0000 |
| Subject: | note 60545 rejected from function.strtotime by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101516@lists.php.net to get a copy of this message | ||
Note Submitter: shaver at qspeed dot com
----
For those upgrading from PHP 4 to PHP 5 there are a number of things that are different about
strtotime that I have NOT seen documented elsewhere, or at least not as clearly. I confirmed these
with two separate fresh installations of PHP 4.4.1 and PHP 5.1.1.
1) Some uppercase and mixed-case strings no longer parse correctly. In php4 "Yesterday"
would parse correctly. In php5 "Yesterday" will return the infamous 1969 date. This is
also true of Tomorrow and Today.
2) You cannot include a space immediately following a + or - in PHP 5. In PHP4 the string
"today + 1 week" works great. in PHP5 the string must be "today +1 week" to
correctly parse.
3) (Partially noted in changelog.) If you pass php4 a string that is a mess ("asdf1234")
it will return -1. If you in turn pass this to date() you'll get a warning like: Windows does
not support dates prior to midnight. This is pretty useful for catching errors in your scripts. In
PHP 5 strtotime will return FALSE which causes date() to return 12/31/69. Note that this is true of
strings that might appear right such as "two weeks".
4) (Partially noted in changelog.) If you pass php4 an empty string it will error out with a
"Notice: strtotime(): Called with empty time parameter". PHP5 will give no notice and
return the current date stamp. (A much preferred behavior IMO.)
5) Given that today is Tuesday: PHP4 "next tuesday" will return today. PHP5 "next
tuesday" will actually return next tuesday as in "today +1week". Note that behavior
has NOT changed for "last" and "this". For the string "last tuesday"
both PHP4 and PHP5 would return "today -1week". For the string "this tuesday"
both PHP4 and PHP5 would return "today".
6. The keyword "previous" is supported in PHP5. (Finally!)
For search engines:
Transition strtotime, Upgrade changes strtotime, migration strtotime, strtotime differences,
uppercase problems, mixed case problems.