baperl has asked for the wisdom of the Perl Monks concerning the following question:

I have the following sql code in my perl file to load time series data into my DB. Unfortunately, the date is formatted as 'dd/mm/yyyy'. ordinarily, I would have chomped the line, split the csv and then written the following
my $trade_dt=UnixDate($tdate,"%Y-%m-%d");
however, I am using the following code to load the data and couldn't get the UnixDate() to work...
LOAD DATA LOCAL INFILE '$fname' INTO TABLE $tname FIELDS TERMINATED BY + ',' (trade_dt,stock_id, volume);
how do I fix the date formatting so the data is inserted in yyyy-mm-dd format

Replies are listed 'Best First'.
Re: date formatting again
by mbethke (Hermit) on Jan 23, 2012 at 05:44 UTC
    Well, if you're bypassing Perl by letting the database server do all the importing, it's no wonder you can't use Perl functions :) What about preprocessing the file? Read each line, split it up, convert the date as you would have otherwise and put it back together. That or insert the data manually using DBI, but preprocessing will likely be both easier and faster.
Re: date formatting again
by roboticus (Chancellor) on Jan 23, 2012 at 11:21 UTC
      I am storing the dates as dates. I did look up the links, thanks for those, @roboticus however, when I run the code by adding @var into my LOAD statement,
      LOAD DATA LOCAL INFILE '$fname' INTO TABLE $tname FIELDS TERMINATED BY + ',' LINES TERMINATED BY '\r\n' (trade_date,....,@var) SET trade_date + = str_to_date(@var, '%d/%m/%Y');
      I get the following error:
      Global symbol "@var" requires explicit package name at process.pl line + 37. Execution of process.pl aborted due to compilation errors.