Reputation: 1298
Hi i have csv file data e.g:- (ActiveDate= 20180105) so I want to save this column to my database. In my database column datatype is datetime .
And while using data conversion as DT_Date i am getting this error:-
The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.
So how can i import this ActiveDate data from my excel to my database as datetime ?
Can you help me out..?
Upvotes: 0
Views: 679
Reputation: 9724
You must first convert Your column YYYYMMDD
To String in Data Conversion
element like this:
Input Column Output Column Data Type Length
IntDate StringDate Unicode string [DT_WSTR] 50
and then you can use this formula in Derived Column
element to convert new string column to real date:
(DT_DATE)(SUBSTRING(StringDate,1,4) + "-" + SUBSTRING(StringDate,5,2) + "-" + SUBSTRING(StringDate,7,2))
For data with null in date column use this formula, this formula gonna change null in current date:
isnull(StringDate)? GETDATE() : (DT_DATE)(SUBSTRING(StringDate,1,4) + "-" + SUBSTRING(StringDate,5,2) + "-" + SUBSTRING(StringDate,7,2))
Results:
IntDate StringDate DateDate
20170809 20170809 2017-08-09 00:00:00.0000000
Upvotes: 1