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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With