Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Numeric Date Validation by dbwiz
in thread Numeric Date Validation by booter

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2021-06-23 21:43 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (122 votes). Check out past polls.