Jump to content



Recommended Posts

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
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


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? 



Link to comment
Share on other sites

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 by Psycho
Link to comment
Share on other sites

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 by kicken
Link to comment
Share on other sites

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.




Thanks for the replies :)

Edited by catsoup
Link to comment
Share on other sites

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().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.