Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Numeric Date Validation

by dbwiz (Curate)
on Sep 30, 2003 at 17:09 UTC ( #295352=note: print w/replies, xml ) Need Help??


in reply to Numeric Date Validation

Date::Manip can do quite a lot, but not everything. Check this test script.

#!/usr/bin/perl -w use strict; use Date::Manip; while (<DATA>) { chomp; my $date = ParseDate($_); if ($date) { print "$_ \t=> ", UnixDate($date,"%b %e, %Y."),"\n"; } else { print "$_ \t=> not a valid date\n"; } } __DATA__ 19971103 11031997 11.03.1997 19983201 20031110 20031011 1993jan02 2002dec08 yesterday today tomorrow Aug12 12Aug2003 Aug122003 122003Aug
output: 19971103 => Nov 3, 1997. 11031997 => not a valid date 11.03.1997 => Nov 3, 1997. 19983201 => not a valid date 20031110 => Nov 10, 2003. 20031011 => Oct 11, 2003. 1993jan02 => Jan 2, 1993. 2002dec08 => Dec 8, 2002. yesterday => Sep 29, 2003. today => Sep 30, 2003. tomorrow => Oct 1, 2003. Aug12 => Aug 12, 2003. 12Aug2003 => Aug 12, 2003. Aug122003 => Aug 12, 2003. 122003Aug => Aug 12, 2003.

Your 11031997 is not recognized as it is, but it is parsed correctly if you add dots. Check the documentation to see which formats are recognized. You see from the example that it is quite flexible.

Be aware, though, that Date::Manip is very slow compared to direct regexp manipulation. Check the docs for this issue as well.

HTH

Replies are listed 'Best First'.
Re: Re: Numeric Date Validation
by jdtoronto (Prior) on Sep 30, 2003 at 19:20 UTC
    Most interesting dbwiz! I will be keeping a copy of this for myself as I had always understood that 11031997 would return 11th March 1997 - I thought it defaulted to ddmmyyyy whereas the behaviour your example shows seem to indicate some ambiguity.

    More testing required here!

    jdtoronto

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://295352]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2021-06-13 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (57 votes). Check out past polls.

    Notices?