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

Reply via email to