tioschi tioschi - 12 days ago 7
MySQL Question

Openoffice-calc can't change the date format of a column

In openoffice calc I open a csv file downloaded from the internet.

One of the columns is for date. The date is in format dd/mm/yy. It is also aligned left (which I think it is saved as text).

I want to modify the date format to yyyy-mm-dd so i can fit it in a mysql table that i have created and in which i hava a column with data type date (so it requires the format i mentioned before).

So I select the column 'Date' in openoffice calc and try to change the format from what it is to the one i want. Nothing is happening. No changes at all.

Any suggestion? Has anything to do with character set or anything like that?

Answer

You could just use MySQL's STR_TO_DATE() function:

LOAD DATA INFILE '/path/to/file.csv'
  INTO TABLE my_table
  CHARACTER SET utf8
  FIELDS
    TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
  LINES
    TERMINATED BY '\r\n'
  IGNORE 1 LINES
  (@date, col_a, col_b, etc)
SET
  date_col = STR_TO_DATE(@date, '%d/%m/%Y')
;