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
strange behavior for strtotime
Moderator: General Moderators
Re: strange behavior for strtotime
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.
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
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.
But based on which character is appended, the hour varies. Certainly nothing in the docs about it.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: strange behavior for strtotime
Very quirky behaviour:
a-m subtract hours, with j messing things up.
n-y add hours
z is ignored
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
n-y add hours
z is ignored
Re: strange behavior for strtotime
RTFM
these are military timezones.