Re: strtotime returns 00:00 for 7am

From: Date: Thu, 21 Jun 2007 23:25:11 +0000
Subject: Re: strtotime returns 00:00 for 7am
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-257625@lists.php.net to get a copy of this message
On 6/20/07, Phil Princely <phil.princely@gmail.com> wrote:
using this code: function test_time($time_string) {
    echo strftime("%X %A, %b %e\n", strtotime($time_string));
You should be testing the strtotime() call's return value, it returns false on failure. if (($timestamp = strtotime($str)) === false) {}
} test_time('now'); test_time('4pm + 2 Hours'); test_time('now + 2 fortnights'); test_time('last Monday'); test_time('tomorrow'); test_time('5am tomorrow'); test_time('7am 12 days ago'); gives this output: 21:46:18 Wednesday, Jun 20 18:00:00 Wednesday, Jun 20 21:46:18 Wednesday, Jul 18 00:00:00 Monday, Jun 18 00:00:00 Thursday, Jun 21 00:00:00 Thursday, Jun 21 07:00:00 Friday, Jun 8 I'm wondering why the 2nd and 3rd last both give 00:00 as the time. Especially why 5am tomorrow doesn't work. Using PHP5.
That false return value I mentioned above becomes a zero when used as the second parameter to strftime(). -- Greg Donald http://destiney.com/

« previous php.general (#257625) next »