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


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.


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.

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:


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

In SSIS you would use the DT_STR or DT_WSTR cast to accomplish. A few examples are

(DT_STR, 4, 1252)YEAR(GETDATE()) + 
RIGHT("0" + (DT_STR, 2, 1252)MONTH(GETDATE()), 2) + 
RIGHT("0" + (DT_STR, 2, 1252)DAY(GETDATE()), 2)


RIGHT("0" + (DT_WSTR, 2)MONTH(GETDATE()),2) + 
RIGHT("0" + (DT_WSTR, 2)DAY(GETDATE()), 2)

See the MSDN documentation for more information.

To add to the other answers, here is a reference guide I use frequently:

Need Your Help

Already Exist Html element reuse using jquery

jquery html jsp

i need to reuse html element using jquery

Differentiate gtk.Entry icons

python icons pygtk gtkentry

I'm adding two icons to a gtk.Entry in PyGTK. The icons signals are handled by the following method