Page 1 of 1

strange behavior for strtotime

Posted: Thu Jan 22, 2009 4:28 pm
by georgewr3
Anyone know why strtotime behaves this way? Adding more than one character causes strtotime to return FALSE.

Code:
print date('Y-m-d H:i:s T', strtotime('2009-01-01 00:00:00')) . "\n";
print date('Y-m-d H:i:s T', strtotime('2009-01-01 00:00:00a')) . "\n";
print date('Y-m-d H:i:s T', strtotime('2009-01-01 00:00:00b')) . "\n";
print date('Y-m-d H:i:s T', strtotime('2009-01-01 00:00:00c')) . "\n";

Result:
2009-01-01 00:00:00 GMT
2008-12-31 23:00:00 GMT
2008-12-31 22:00:00 GMT
2008-12-31 21:00:00 GMT

Re: strange behavior for strtotime

Posted: Thu Jan 22, 2009 5:14 pm
by requinix
Doesn't look like it's returning false to me.

Not sure what the a, b, c signals (can't find the GNU page about this anymore) but it's not causing an error.

Re: strange behavior for strtotime

Posted: Fri Jan 23, 2009 7:36 am
by georgewr3
Right, it doesn't return false if a single character is appended. More than one character appended does return FALSE. And that single character has to trail a valid timestamp.

But based on which character is appended, the hour varies. Certainly nothing in the docs about it.

Re: strange behavior for strtotime

Posted: Fri Jan 23, 2009 7:46 am
by Mark Baker
Very quirky behaviour:

Code: Select all

 
2009-01-01 00:00:00a => 2008-12-31 23:00:00 GMT
2009-01-01 00:00:00b => 2008-12-31 22:00:00 GMT
2009-01-01 00:00:00c => 2008-12-31 21:00:00 GMT
2009-01-01 00:00:00d => 2008-12-31 20:00:00 GMT
2009-01-01 00:00:00e => 2008-12-31 19:00:00 GMT
2009-01-01 00:00:00f => 2008-12-31 18:00:00 GMT
2009-01-01 00:00:00g => 2008-12-31 17:00:00 GMT
2009-01-01 00:00:00h => 2008-12-31 16:00:00 GMT
2009-01-01 00:00:00i => 2008-12-31 15:00:00 GMT
2009-01-01 00:00:00j => 1970-01-01 01:00:00 BST
2009-01-01 00:00:00k => 2008-12-31 14:00:00 GMT
2009-01-01 00:00:00l => 2008-12-31 13:00:00 GMT
2009-01-01 00:00:00m => 2008-12-31 12:00:00 GMT
2009-01-01 00:00:00n => 2009-01-01 01:00:00 GMT
2009-01-01 00:00:00o => 2009-01-01 02:00:00 GMT
2009-01-01 00:00:00p => 2009-01-01 03:00:00 GMT
2009-01-01 00:00:00q => 2009-01-01 04:00:00 GMT
2009-01-01 00:00:00r => 2009-01-01 05:00:00 GMT
2009-01-01 00:00:00s => 2009-01-01 06:00:00 GMT
2009-01-01 00:00:00t => 2009-01-01 07:00:00 GMT
2009-01-01 00:00:00u => 2009-01-01 08:00:00 GMT
2009-01-01 00:00:00v => 2009-01-01 09:00:00 GMT
2009-01-01 00:00:00w => 2009-01-01 10:00:00 GMT
2009-01-01 00:00:00x => 2009-01-01 11:00:00 GMT
2009-01-01 00:00:00y => 2009-01-01 12:00:00 GMT
2009-01-01 00:00:00z => 2009-01-01 00:00:00 GMT
 
a-m subtract hours, with j messing things up.
n-y add hours
z is ignored

Re: strange behavior for strtotime

Posted: Sat Jan 24, 2009 9:17 pm
by Popcorn
RTFM ;) these are military timezones.