catsoup Posted August 29, 2013 Share Posted August 29, 2013 Hi All, What do you think this should give? : echo strtotime('I'); (Thats a capital 'i') On my PHP 5.2.6 and PHP 5.3.3 and system, it seems to give a time nine hours previously: $ cat test.php <?php date_default_timezone_set('UTC'); $s="I"; echo "strtotime('$s')=".strtotime($s)."\n"; echo "date(strtotime('$s'))=".date(DATE_RFC822,strtotime($s))."\n"; echo "now=".date(DATE_RFC822)."\n"; $ php test.php strtotime('I')=1377749122 date(strtotime('I'))=Thu, 29 Aug 13 04:05:22 +0000 now=Thu, 29 Aug 13 13:05:22 +0000 Anyone know what format of date/time a single capital 'I' is matching? Cheers! Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 29, 2013 Share Posted August 29, 2013 (edited) I don't know it would return anything useful. strtotime() expects a string that is in a date/time format. E.g. strtotime('5-15-2013'), strtotime('10:14:23'), strtotime('2010-8-23 22:35:10'), etc. What are you expecting an uppercase I to return? Are you maybe confusing the input parameter with what would be used for the date() function? For date(), the uppercase I would return 1/0 based upon whether the date/time is within daylight savings time. You can find more information regarding the supported formats here: http://us1.php.net/manual/en/datetime.formats.php EDIT: IT does look like you can use alpha characters for the input - but I don't see a single "I" as a valid value. There are references to double "I"s though Edited August 29, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
kicken Posted August 29, 2013 Share Posted August 29, 2013 (edited) Supposedly it supports roman-numeral style month names, which 'I' would fall under, but the output doesn't seem to match with that action. If you run through 'a' - 'z', all except 'j' return a value of some kind however I cannot see any particular reason for the values they return. Such an input is unexpected and probably causes the parser to do something odd. If you really want to know what is happening, compile a debug version of PHP, set a breakpoint at the date parser function, and step through it Edited August 29, 2013 by kicken Quote Link to comment Share on other sites More sharing options...
catsoup Posted September 2, 2013 Author Share Posted September 2, 2013 (edited) Thanks for the replies, I would actually prefer it to return false for a string like "I " rather than a date. The code I have is checking for dates embeded in text, and they will always be at the start of a string. Unfortunately the date can be just about any format the users PC has it set to, so I cant look for specific formats. I realise that 100% accuracy is therfore not possible, but 99% will do I did consider it was considering it to be roman numerals, but 'IV', 'V' or 'II' does return false, so I gave up on that idea. For now, I will leave my code checking for 'I<space>' at the start of a string. Not pretty, but I dont have time right now to step through the PHP souce. Anyway, Thanks for the replies Edited September 2, 2013 by catsoup Quote Link to comment Share on other sites More sharing options...
objnoob Posted September 2, 2013 Share Posted September 2, 2013 i wouldn't use strtotime to validate a supported date/time format. I would first validate the date/time format is supported, then use strtotime() to handle the conversion. if i needed to allow for custom date/time formats not supported by strtotime(), I would validate custom format is valid, convert to a strtotime() supported date/time format, then use strtotime() to handle conversion. except, i really wouldn't. i'd parse out the date/time parts and use mktime(). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.