Re: strtotime - assumptions about default formatting of dates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 24/12/09 16:59, Bastien Koert wrote:
On Thu, Dec 24, 2009 at 9:12 AM, tedd<tedd.sperling@xxxxxxxxx>  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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux