943,696 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1739
  • MySQL RSS
Aug 28th, 2009
0

Mysql: importing .csv file with date.

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajuchacha007 is offline Offline
19 posts
since Aug 2009
Aug 29th, 2009
0

Re: Mysql: importing .csv file with date.

Elaborate some more please.

How are importing the csv file into mysql?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 30th, 2009
0

Re: Mysql: importing .csv file with date.

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajuchacha007 is offline Offline
19 posts
since Aug 2009
Aug 31st, 2009
0

Re: Mysql: importing .csv file with date.

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
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Sep 2nd, 2009
0

Re: Mysql: importing .csv file with date.

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

Quote ...
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;
Reputation Points: 22
Solved Threads: 9
Junior Poster in Training
varmadba is offline Offline
83 posts
since Jun 2008
Sep 2nd, 2009
0

Re: Mysql: importing .csv file with date.

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.

Click to Expand / Collapse  Quote originally posted by varmadba ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rajuchacha007 is offline Offline
19 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Image as an argument to the stored procedure
Next Thread in MySQL Forum Timeline: Moving MySQL Data from Linux to Windows Computer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC