
strtotime - assumptions about default formatting of dates
------=_NextPart_000_05B6_01CA84E7.4917D190
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi all. I need to allow users to enter dates and times, and for a while =
now I've been forcing them to use javascript date/time pickers so I can =
be absolutely sure the formatting is correct.
Some users are requesting to be able to type the entries themselves so =
I've decided to allow this.
I'm in Australia, and the standard formatting of dates here is =
DD/MM/YYYY or DD-MM-YYYY
I recognize this is different to what seems to happen in the US, where =
it is MM/DD/YYYY or MM-DD-YYYY
When I process an entered date using strtotime() it seems to work fine.
But of course I am concerned when dates like January 2 come up.
I find that 2/1/2009 is interpreted as January 2, 2009 on my =
installation, which is Windows 7 with location set to Australia.
But can I be sure that all installations of PHP, perhaps in different =
countries and on different operating systems will interpret dates the =
same?
I can't find much mention of this question online or in the manual.
Any help much appreciated.
Angus
------=_NextPart_000_05B6_01CA84E7.4917D190--
Re: strtotime - assumptions about default formatting of dates
On 24/12/09 12:20, Angus Mann wrote:
> Hi all. I need to allow users to enter dates and times, and for a while now I've been forcing them to use javascript date/time pickers so I can be absolutely sure the formatting is correct.
>
> Some users are requesting to be able to type the entries themselves so I've decided to allow this.
>
> I'm in Australia, and the standard formatting of dates here is DD/MM/YYYY or DD-MM-YYYY
>
> I recognize this is different to what seems to happen in the US, where it is MM/DD/YYYY or MM-DD-YYYY
>
> When I process an entered date using strtotime() it seems to work fine.
>
> But of course I am concerned when dates like January 2 come up.
>
> I find that 2/1/2009 is interpreted as January 2, 2009 on my installation, which is Windows 7 with location set to Australia.
>
> But can I be sure that all installations of PHP, perhaps in different countries and on different operating systems will interpret dates the same?
>
> I can't find much mention of this question online or in the manual.
>
> Any help much appreciated.
> Angus
>
I wrote a little AJAX gadget which sent the string typed to a PHP backend which
parsed it using strtotime and then formatting it out again as something
unamiguous (like 2 January 2009). Then every time the date entry field is
changed by the user (with an onKeyUp event), this AJAX call is triggered and
displays the unambiguous form next to the input box, so users can see how their
entry is being interpreted.
Of course, there's some overhead in the AJAX calls, and it requires JavaScript.
If you wanted to do without JavaScript you could do a similar parse-format
sequence when the form is submitted and show a confirmation page with your
server's interpretation of the date.
Cheers
Pete
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: strtotime - assumptions about default formatting of dates
On Thu, Dec 24, 2009 at 13:20, Angus Mann <angusmann [at] pobox.com> wrote:
> Hi all. I need to allow users to enter dates and times, and for a while now I've been forcing them to use javascript date/time pickers so I can be absolutely sure the formatting is correct.
>
> Some users are requesting to be able to type the entries themselves so I've decided to allow this.
>
> I'm in Australia, and the standard formatting of dates here is DD/MM/YYYY or DD-MM-YYYY
>
> I recognize this is different to what seems to happen in the US, where it is MM/DD/YYYY or MM-DD-YYYY
>
> When I process an entered date using strtotime() it seems to work fine.
>
> But of course I am concerned when dates like January 2 come up.
>
> I find that 2/1/2009 is interpreted as January 2, 2009 on my installation, which is Windows 7 with location set to Australia.
>
> But can I be sure that all installations of PHP, perhaps in different countries and on different operating systems will interpret dates the same?
>
> I can't find much mention of this question online or in the manual.
>
> Any help much appreciated.
> Angus
>
strtotime() interprets dates according to the rules of the current
timezone. The specific rules are outlined in GNU's manual:
http://www.gnu.org/software/tar/manual/html_node/Date-input- formats.html
--
Daniel Egeberg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: strtotime - assumptions about default formatting ofdates
At 10:20 PM +1000 12/24/09, Angus Mann wrote:
>Hi all. I need to allow users to enter dates and times, and for a
>while now I've been forcing them to use javascript date/time pickers
>so I can be absolutely sure the formatting is correct.
>
>Some users are requesting to be able to type the entries themselves
>so I've decided to allow this.
>
>I'm in Australia, and the standard formatting of dates here is
>DD/MM/YYYY or DD-MM-YYYY
>
>I recognize this is different to what seems to happen in the US,
>where it is MM/DD/YYYY or MM-DD-YYYY
>
>When I process an entered date using strtotime() it seems to work fine.
>
>But of course I am concerned when dates like January 2 come up.
>
>I find that 2/1/2009 is interpreted as January 2, 2009 on my
>installation, which is Windows 7 with location set to Australia.
>
>But can I be sure that all installations of PHP, perhaps in
>different countries and on different operating systems will
>interpret dates the same?
>
>I can't find much mention of this question online or in the manual.
>
>Any help much appreciated.
>Angus
Angus:
You are running into a problem that cannot be solved by allowing the
user to do whatever they want. As you realize, if I enter 01-02-09
you don't know if I mean January 2, 2009 or February 1, 2009 and
there is no way to figure out what I meant.
The solution is simply to use the html <option> and give the user
that way to enter month and day.
I would set it to day-month-year and let US visitors live with it for
I personally think that's a better format.
Cheers and Merry Christmas.
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: strtotime - assumptions about default formatting of dates
On Thu, Dec 24, 2009 at 9:12 AM, tedd <tedd.sperling [at] gmail.com> wrote:
> At 10:20 PM +1000 12/24/09, Angus Mann wrote:
>>
>> Hi all. I need to allow users to enter dates and times, and for a while
>> now I've been forcing them to use javascript date/time pickers so I can =
be
>> absolutely sure the formatting is correct.
>>
>> Some users are requesting to be able to type the entries themselves so
>> I've decided to allow this.
>>
>> I'm in Australia, and the standard formatting of dates here is DD/MM/YYY=
Y
>> or DD-MM-YYYY
>>
>> I recognize this is different to what seems to happen in the US, where i=
t
>> is MM/DD/YYYY or MM-DD-YYYY
>>
>> When I process an entered date using strtotime() it seems to work fine.
>>
>> But of course I am concerned when dates like January 2 come up.
>>
>> I find that 2/1/2009 is interpreted as January 2, 2009 on my installatio=
n,
>> which is Windows 7 with location set to Australia.
>>
>> But can I be sure that all installations of PHP, perhaps in different
>> countries and on different operating systems will interpret dates the sa=
me?
>>
>> I can't find much mention of this question online or in the manual.
>>
>> Any help much appreciated.
>> Angus
>
> Angus:
>
> You are running into a problem that cannot be solved by allowing the user=
to
> do whatever they want. As you realize, if I enter 01-02-09 you don't know=
if
> I mean January 2, 2009 or February 1, 2009 and there is no way to figure =
out
> what I meant.
>
> The solution is simply to use the html <option> and give the user that wa=
y
> to enter month and day.
>
> I would set it to day-month-year and let US visitors live with it for I
> personally think that's a better format.
>
> Cheers and Merry Christmas.
>
> tedd
>
>
> --
> -------
> http://sperling.com =A0http://ancientstones.com =A0http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I would agree with tedd. Use a JS calendar widget (requires js) or use
three select boxes for mm , dd and year
--
Bastien
Cat, the other other white meat
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: strtotime - assumptions about default formatting of dates
> I wrote a little AJAX gadget which sent the string typed to a PHP backend
> which parsed it using strtotime and then formatting it out again as
> something unamiguous (like 2 January 2009). Then every time the date entry
> field is changed by the user (with an onKeyUp event), this AJAX call is
> triggered and displays the unambiguous form next to the input box, so
> users can see how their entry is being interpreted.
> Of course, there's some overhead in the AJAX calls, and it requires
> JavaScript.
>
> If you wanted to do without JavaScript you could do a similar parse-format
> sequence when the form is submitted and show a confirmation page with your
> server's interpretation of the date.
>
> Cheers
> Pete
I took this idea and wrote an ajax so that on keyup or blur, the entry is
sent to PHP which puts it into strtotime() and if a valid result comes out,
formats it something like "Wed January 23, 2008 6:23pm". If the result is
invalid, it outputs an "Invalid" message. This is then displayed in a span
next to the textbox.
So as the user types they can see if what they entered is valid, and also
see how the date/time will be interpreted. Works beautifully, and makes the
form very usable.
For what it's worth, here is the code:
The PHP ajax (called judgedatetime.php:
-----------
$inp=$_REQUEST['a'];
$a=strtotime($inp);
if ($a < 1200103200){
$b="Invalid";
} else {
$b=date("D M j, Y g:ia",$a);
}
echo $b;
?>
The Javascript
---------------
function assessdtime(dTime,putHere){
AjaxRequest.get({'url':'ajax/judgedatetime.php',
'parameters':{'a':dTime},
'onSuccess':function(req){
document.getElementById(putHere).innerHTML=req.responseText;
}
})}
And HTML embedded in the page..
-----------------------------------
<input type="text" size="14" id="start" name="start"
onkeyup="assessdtime(this.value,'startreport');"
onblur="assessdtime(this.value,'startreport');" />
<span id="startreport">Enter a date and time</span>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: strtotime - assumptions about default formatting of dates
On 24/12/09 16:59, Bastien Koert wrote:
> On Thu, Dec 24, 2009 at 9:12 AM, tedd<tedd.sperling [at] gmail.com> wrote:
>> At 10:20 PM +1000 12/24/09, Angus Mann wrote:
>>>
>>> Hi all. I need to allow users to enter dates and times, and for a while
>>> now I've been forcing them to use javascript date/time pickers so I can be
>>> absolutely sure the formatting is correct.
>>>
>>> Some users are requesting to be able to type the entries themselves so
>>> I've decided to allow this.
>>>
>>> I'm in Australia, and the standard formatting of dates here is DD/MM/YYYY
>>> or DD-MM-YYYY
>>>
>>> I recognize this is different to what seems to happen in the US, where it
>>> is MM/DD/YYYY or MM-DD-YYYY
>>>
>>> When I process an entered date using strtotime() it seems to work fine.
>>>
>>> But of course I am concerned when dates like January 2 come up.
>>>
>>> I find that 2/1/2009 is interpreted as January 2, 2009 on my installation,
>>> which is Windows 7 with location set to Australia.
>>>
>>> But can I be sure that all installations of PHP, perhaps in different
>>> countries and on different operating systems will interpret dates the same?
>>>
>>> I can't find much mention of this question online or in the manual.
>>>
>>> Any help much appreciated.
>>> Angus
>>
>> Angus:
>>
>> You are running into a problem that cannot be solved by allowing the user to
>> do whatever they want. As you realize, if I enter 01-02-09 you don't know if
>> I mean January 2, 2009 or February 1, 2009 and there is no way to figure out
>> what I meant.
>>
>> The solution is simply to use the html<option> and give the user that way
>> to enter month and day.
>>
>> I would set it to day-month-year and let US visitors live with it for I
>> personally think that's a better format.
>>
>> Cheers and Merry Christmas.
>>
>> tedd
>>
>>
>> --
>> -------
>> http://sperling.com http://ancientstones.com http://earthstones.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> I would agree with tedd. Use a JS calendar widget (requires js) or use
> three select boxes for mm , dd and year
>
I developed my little text input AJAX (see earlier post) to work around the fact
that a LOT of users I encountered were cheesed off by JS calendar widgets,
especially when the date to be entered was a long way from the current date
(such as a date of birth). I tried implementing some scroll-wheel events to
speed up year selection on one of these but it was tricky to get cross-browser
support.
Drop-downs are a pain when you have to scroll back 40+ years to find the right
one and are implicitly limited by how far back and forward the designer expects
to need, and then you have the problem of validating the days and months (which,
to be fair, is a pretty simple javascript task)
I suspect that with a bit of thought I could put together a Javascript date
validator that parsed most possible inputs and produced a sensible
interpretation of them, but I was lazy and had AJAX machinery set up already in
my project.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php