Hi

There ae a number of posts on this site on how to validate dates - and they seems to be based on the notion that the date format is known in advance (e.g. checking for valid date).

I have a slightly different situation. I need to validate dates in any number of different files, which can have dates in a number of different formats. I know the posix date format of each date field (e.g. '%d/%m/%Y'), so I have been doing this

my $strp = DateTime::Format::Strptime->new(pattern => $pattern); ... my $dt = $strp->parse_datetime($value) || <handle error>;

Of course, creating a DateTime object for each field a validate is quite expensive, and it takes too long to run this even a moderately sized file. Does anyone know of another routine that can validate a date against a posix format? Note I can't use something like Date::Manip to intuit the date, because it can't handle some of my cases(d/m/y v m/d/y), whereas the posix string can be used to explicitly state the format.

Thanks


In reply to Fast way to validate dates by astroboy

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.