note 60545 added to function.strtotime

From: Date: Tue, 10 Jan 2006 20:01:12 +0000
Subject: note 60545 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-101514@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60545 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60545&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60545&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60545&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60545&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60545&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60545&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60545&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60545&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101514) next »