Click here to get back home

Handle multiple input date formats?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Handle multiple input date formats? fishfry 09-11-2004
Get Chitika Premium
Posted by fishfry on September 11, 2004, 11:56 am
Please log in for more thread options
I have a date input field and I want to be able to handle 3/22/04,
22-mar-04, March 22, 2004, etc. I looked through the Module List and
there are dozens of Date/Time routines but no way to figure out which,
if any, will do what I want.

Clues for me please?


Posted by Jürgen Exner on September 11, 2004, 1:40 pm
Please log in for more thread options
fishfry wrote:
> I have a date input field and I want to be able to handle 3/22/04,

Would this be the 22 of April in the year 2003 or the 22 of March in year
2004?

And you are lucky that there are no 22 months in the year. If you would have
used e.g. 05 instead in your example, then this would be 3rd of May 2004 in
most parts of the world.
And of course this doesn't even begin to address the complexity of any but
the Gregorian calender, e.g. the Hebrew calender, the Islamic calender, the
Japanese imperial calender, etc, etc. are left out.

If you allow a free form text field for date entry then the values you
receive will be useless.

> 22-mar-04, March 22, 2004, etc. I looked through the Module List and
> there are dozens of Date/Time routines but no way to figure out which,
> if any, will do what I want.
>
> Clues for me please?

Familiarize yourself with date formats that people actually use and you will
notice that an automatic "detection" ends up being an automated guess.

_YOU_ must define and enforce the format or people will enter dates in any
of dozens of ambiguous formats where no software or human can make a safe
call. You could just as well use a rand(), that's easier to do.

jue





Posted by Gunnar Hjalmarsson on September 11, 2004, 8:49 pm
Please log in for more thread options
Jürgen Exner wrote:
> fishfry wrote:
>> I have a date input field and I want to be able to handle
>> 3/22/04,
>
> If you allow a free form text field for date entry then the values
> you receive will be useless.
>
> _YOU_ must define and enforce the format or people will enter dates
> in any of dozens of ambiguous formats where no software or human
> can make a safe call.

To the OP:
Even if I chose to answer your question directly, I agree with Jürgen.
What you are trying to do appears to be a bad idea.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Posted by Gunnar Hjalmarsson on September 11, 2004, 2:34 pm
Please log in for more thread options
fishfry wrote:
> I have a date input field and I want to be able to handle 3/22/04,
> 22-mar-04, March 22, 2004, etc. I looked through the Module List
> and there are dozens of Date/Time routines but no way to figure out
> which, if any, will do what I want.

No way? Of course there is. One way is to browse the descriptions at
http://search.cpan.org/.

> Clues for me please?

http://search.cpan.org/perldoc?Date%3A%3AParse

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Posted by Charles DeRykus on September 11, 2004, 10:34 pm
Please log in for more thread options
> I have a date input field and I want to be able to handle 3/22/04,
>22-mar-04, March 22, 2004, etc. I looked through the Module List and
>there are dozens of Date/Time routines but no way to figure out which,
>if any, will do what I want.
>

I agree with suggestions to enforce the format but you
may find Date::Manip useful for dealing with potential
variability.

For instance, if you specify "month day year", Date::Manip
handles several variants:

# perl -MDate::Manip -le 'print &ParseDate("3/22/04")'
2004032200:00:00

# perl -MDate::Manip -le 'print &ParseDate("March 22, 2004")'
2004032200:00:00

# perl -MDate::Manip -le 'print &ParseDate("mar-22-04")'
2004032200:00:00

perl -MDate::Manip -le 'print &ParseDate("03.22.04")'
2004032200:00:00

--
Charles DeRykus




Similar ThreadsPosted
How to handle input and output of a program executed by System function in perl July 18, 2004, 2:31 pm
XML::Twig parseurl with input Headers/XML January 16, 2005, 10:58 pm
reading from Net::Telnet input string problem June 16, 2006, 1:17 pm
AI::NNFLex , sum net - why doen't read correct @input set ? July 2, 2006, 10:54 am
No clickable input with activeperl mechanize.pm at line 1345 November 18, 2005, 1:54 pm
HTTP::Request::Form - Problem pressing input type=image button February 1, 2005, 7:56 am
Tie::Handle::CSV Help... July 23, 2006, 2:00 pm
Tie::Handle::CSV and newlines February 1, 2007, 1:47 am
Archive::Tar and how to handle *.bz2 archives? September 13, 2005, 3:18 pm
Date::MSAccess V 1.01 July 29, 2004, 7:15 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap