Esteemed monks,

I have an application that imports a CSV file into a MySQL table where all fields are varchar type. One field has a date in the format 'MM/DD/CCYY hh:mm' where leading zeroes are typically not present. This needs to be converted to something that MySQL will swallow - such as: 'CCYY-MM-DD hh:mm:ss' where all zeroes are required.

I can get the various parts of the time using split and then rebuilding the string. BUT there are typically somewhere between 7000 and 500000 records in the table.

I am assuming that doing a SELECT and getting the key and the date as text field into a HASH - then convert the date format - the do an UPDATE will be the best way of doing the change?

App is in Perl 5.8.0 using DBI/DBD-MySQL.

Your advice is sought on

jdtoronto

In reply to Convert date format in database table. by jdtoronto

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.