Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS - cast a date to use in an expression

I want to cast a date into ISO format, and use it as a string in an expression in SSIS.

This is what I type in T-SQL

select convert(varchar(8), GetDate(), 112)

and this is what I get back

20100630

My goal - is to create an archive folder based on the date. I have the File System Task part of creating a folder sorted, I can do that ... I just need to be able to Cast the date to a string, so I can use that.

Thanks in advance.

like image 914
cometbill Avatar asked Dec 01 '25 07:12

cometbill


2 Answers

Old question, better-er answer, from Adrian's comment here:

Try an intermediate cast to type DT_DBDATE. Casting to WSTR gives a string in format "YYYY-MM-DD", which is easily tidied up:

REPLACE((DT_WSTR,200)(DT_DBDATE)GETUTCDATE(),"-","")

Or use without the REPLACE to get the YY-MM-DD

like image 88
Jeff Avatar answered Dec 03 '25 17:12

Jeff


You'll need to add an expression:

RIGHT((DT_WSTR, 4) DATEPART("yyyy", GetDate()), 4) + 
RIGHT("0" + (DT_WSTR,2)DatePart("mm", GetDate()), 2) + 
RIGHT("0" + (DT_WSTR,2)DatePart("dd", GetDate()), 2)

This expression will create the result that you are after.

like image 33
Neil Knight Avatar answered Dec 03 '25 16:12

Neil Knight



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!