Mysql: importing .csv file with date.

Reply

Join Date: Aug 2009
Posts: 19
Reputation: rajuchacha007 is an unknown quantity at this point 
Solved Threads: 0
rajuchacha007 rajuchacha007 is offline Offline
Newbie Poster

Mysql: importing .csv file with date.

 
0
  #1
Aug 28th, 2009
Hello,

I am importing a .csv file in mysql. I am facing problem when it comes to date. Let me elaborate.

CaptureDate
20071101
20071101
20071101
20071101
20071101

This is data. But when i Load the file,
it displays only last record correctly but not the rest 4. Please help. Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Mysql: importing .csv file with date.

 
0
  #2
Aug 29th, 2009
Elaborate some more please.

How are importing the csv file into mysql?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 19
Reputation: rajuchacha007 is an unknown quantity at this point 
Solved Threads: 0
rajuchacha007 rajuchacha007 is offline Offline
Newbie Poster

Re: Mysql: importing .csv file with date.

 
0
  #3
Aug 30th, 2009
Hello,

I am importing a in.csv file in mysql. I t contains one variable called CaptureDate.

load data infile 'C\in.csv' into table table name
lines terminated by '\n'
ignore 1 lines;

Once I executed, I got errors like row 1 doesn't contain data for all columns. I changed the data types from date to varchar,long and numeric but still not able to resolve he problem. Later I tried to use str_to_date(). But still not able to get it executed. Please advise. Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Mysql: importing .csv file with date.

 
0
  #4
Aug 31st, 2009
I think your problem has to with with how the date is formatted in your csv file:

20071101

Ideally that should be:

2007-11-01
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: varmadba is an unknown quantity at this point 
Solved Threads: 8
varmadba varmadba is offline Offline
Junior Poster in Training

Re: Mysql: importing .csv file with date.

 
0
  #5
Sep 2nd, 2009
work around would be to

Create a column CaptureDate of type varchar or char
once import is done u can update the data and get it in date time format

alter table table1 add column CaptureDate_1 date;
update table1 set CaptureDate_1=date_format(CaptureDate,'%Y-%m-%d')
alter table table1 drop column CaptureDate;
:- Varma

We are Happy to inform launch of a new site with loads of database related information Site offers wide range of functionality Forums,Blogs,Articles,Editorials and much more
http://www.sqllibrarian.info/
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 19
Reputation: rajuchacha007 is an unknown quantity at this point 
Solved Threads: 0
rajuchacha007 rajuchacha007 is offline Offline
Newbie Poster

Re: Mysql: importing .csv file with date.

 
0
  #6
Sep 2nd, 2009
Thanks Varmadba. I got the result with the same technique. What I did was
load data infile 'c:\in.csv' into table riamp_in_stage
-> fields terminated by ','
-> lines terminated by '\n'
-> (@CaptureDate)
-> set CaptureDate=str_to_date(@CaptureDate,'%Y%m%d');
Thank you very much for your response.

Originally Posted by varmadba View Post
work around would be to

Create a column CaptureDate of type varchar or char
once import is done u can update the data and get it in date time format
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC