I am using Spreadsheet::ParseExcel to read data from an excel spreadsheet. I have encountered a problem ingesting dates. The excel date format is mm/dd/yyyy whereas mysql expects yyyy-mm-dd. I tried reformating the cells in the spreadsheet and I can, in fact, format the presentation of the date to match the yyyy-mm-dd format that mysql expects, but when I select a cell it turns out the cell content is still in the mm/dd/yyyy format. Therefore, when attempt to insert the dates into mysql I only get 0000-00-00. I am attempting to use the STR_TO_DATE mysql function within my DBI do statement to correct this problem. My code looks like this:
$dbh->do("insert into frame (indate,siteid,serial,contract,installdate) values (CURDATE(),\'$frame_siteid\',\'$frame_serial\',\'$frame_contract\',STR +_TO_DATE($frame_installdate,\'%m/%d/Y\')");
However, this date formatting syntax is failing:
DBD::mysql::db do failed: You have an error in your SQL syntax; check +the manual that corresponds to your MySQL server version for the righ +t syntax to use near '' at line 3 at ./excel.syr.frame.extract.pl lin +e 91.
I imagine this is a common problem for which there is a common answer, but I am having trouble finding it on the mysql or perl sites/reference material I have searched.
Hagen Finley

In reply to DBI:mysql date conversion question by finhagen

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.