convert mm/dd/yyyy to yyyy-mm-dd in ssis

HI All,

I have an csv file with date column in the following format mm/dd/yyyy, i need to convert that date column to the following format yyyy-mm-dd HH:mm:ss, before loading it into oledb destination. i have used derived column transformation for this purpose and tried out the following expression

(DT_DATE)("20" + SUBSTRING(ReceivedDateTime,1,2) + "-" + SUBSTRING(ReceivedDateTime,3,2) + "-" + SUBSTRING(ReceivedDateTime,5,2)) it is throwing error like unable to perform type cast.

more ▼

asked Apr 21, 2012 at 02:22 PM in Default

satish24707 gravatar image

0 2 2 2

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You have wrong expression. You have mentioned, you have date in formant "mm/dd/yyy" and based on your expression you will receive below string for eg.

"04/25/2012" => "20" + "04" + "-" + "/2" + "-" + "5/" => "2004-/2-5/"

And the string "2004-/2-5/" is not convertible into date.

Correct expresstions should look like:

(DT_DATE)(RIGHT(ReceivedDateTime,4) + "/" + LEFT(ReceivedDateTime,2) + "/" + SUBSTRING(ReceivedDateTime,4,2))


(DT_DATE)(SUBSTRING(ReceivedDateTime,7,4) + "/" + SUBSTRING(ReceivedDateTime,1,2) + "/" + SUBSTRING(ReceivedDateTime,4,2))
more ▼

answered Apr 23, 2012 at 06:03 AM

Pavel Pawlowski gravatar image

Pavel Pawlowski
22.3k 9 11 21

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Apr 21, 2012 at 02:22 PM

Seen: 995 times

Last Updated: Apr 23, 2012 at 06:03 AM