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
am 24.12.2009 14:42:42 von Pete Ford
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
am 24.12.2009 14:51:56 von Daniel Egeberg
On Thu, Dec 24, 2009 at 13: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
>
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
am 24.12.2009 15:12:20 von TedD
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
Re: strtotime - assumptions about default formatting of dates
am 24.12.2009 17:59:04 von Phpster
On Thu, Dec 24, 2009 at 9:12 AM, tedd 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
Re: Re: strtotime - assumptions about default formatting of dates
am 25.12.2009 01:50:18 von Angus Mann
> 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..
-----------------------------------
onkeyup="assessdtime(this.value,'startreport');"
onblur="assessdtime(this.value,'startreport');" /> Enter a date and time
--
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
am 04.01.2010 10:57:41 von Pete Ford
On 24/12/09 16:59, Bastien Koert wrote:
> On Thu, Dec 24, 2009 at 9:12 AM, tedd 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