Not quite on point but something you might find some use in and I had lying around (tweaked it minorly for this). The following script parses dates, in all manner of formats, into something useable by mySQL. If it fails, you'd know you had nothing good.

sample usage (readmore for code)

user[29]~/bin>mysql-date-fixer next tuesday 2003-04-29 01:06:55 user[30]~/bin>mysql-date-fixer Jan 1 2021 2021-01-01 00:00:00 user[31]~/bin>mysql-date-fixer 982321156 2001-02-16 03:59:16

code

# script name mysql-date-fixer # NB: Date::Manip is great but it is slow, and this is fun code # but just something i did to play with Date::Manip and not # that polished use Date::Manip; use warnings; use strict; my $date; my $date_thing_to_check = join(' ', @ARGV); unless ( $date_thing_to_check ) { print "What date are you trying to figure out?\n\t"; chomp ($date_thing_to_check = <STDIN>); } # string of numbers not like 200304242116, we'll call it epoch secs if ( $date_thing_to_check =~ /^(?!19|20)\d{7,10}$/ ) { $date = ParseDateString("epoch $date_thing_to_check"); $date = ParseDate($date); } else { # something date-ish, ParseDate is very forgiving $date = ParseDate($date_thing_to_check); } unless ( $date ) { die "I couldn't figure that one out...\n", "\tPlease try again with simplified input, ", "write numbers in Arabic.\n"; } # a mySQL format, YYYY-MM-DD HH:MM:SS print UnixDate( $date,"%Y-%m-%d %H:%M:%S"), "\n";

In reply to (Date) Data format verification for insertion into a database by Your Mother
in thread Data format verification for insertion into a database by antirice

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.