strange behavior for strtotime

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
georgewr3
Forum Newbie
Posts: 9
Joined: Fri Jan 16, 2009 12:57 pm

strange behavior for strtotime

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: strange behavior for strtotime

Post 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.
georgewr3
Forum Newbie
Posts: 9
Joined: Fri Jan 16, 2009 12:57 pm

Re: strange behavior for strtotime

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: strange behavior for strtotime

Post 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
User avatar
Popcorn
Forum Commoner
Posts: 55
Joined: Fri Feb 21, 2003 5:19 am

Re: strange behavior for strtotime

Post by Popcorn »

RTFM ;) these are military timezones.
Post Reply