After i imported a large csv into a table i ran into a major problem in my case:
the format of the date in the csv it’s DD MM YYYY, and when i try importing that into a date/datetime it won’t work. So ok I did it with a CHAR type instead of DATE/DATETIME and it works so far. (my example: VisitTime CHAR(10) )
BUT here is the problem, with the data inside the CHAR I can’t concatenate to make a datetime column from 2 columns ( my example is: VisitTime CHAR(10) which was supposed to be DATE but isn’t working since it’s wrong format DD MM YYYY and HourTime which is TIME.
Bottom line: i need a column in another table VisitTimeandHour DATETIME which results from a concatenation of VisitTIME CHAR(10) and a HourTime TIME.
A solution was maybe making all the columns that i talked about VARCHAR and it was i think no problem, but i wanna stick with date and datetime 🙂
Waiting for solutions, thanks in advance.
Correct me if i’m wrong but if i try to import into a variable then converting it would be ok?, and by the way an example of date that needs to be converted from the csv is: 22/04/2005 ) the code:
SET @var1 = NULL;
load data infile ‘xxxx/xxx/xxx/xxx/xxx’
into table vizite_intermtest
character set utf8
fields terminated by ‘,’
lines terminated by ‘\n’
ignore 1 lines
(@var1,OraIntrare,NumePacient,PrenumePacient,NumeMedic,PrenumeMedic,Cabinet)
SET VisitTime = STR_TO_DATE(@var1, ‘%d/%m/%y’);
If i try this it says: truncated inccorect value 22/04/2005 (the VisitTime column that i wanna import in it’s a CHAR type)
LE: It works to import into a variable and to convert it but altough i put the / / / between them it still gives me the time format with – – – … any ideas?
You should stick with the DATE / DATETIME fields, but tell MySQL how to interpret the incoming data. I’m not certain how you imported the data, but the function to interpret a string as a date is
STR_TO_DATE:For more info, see the following:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date