Monday, 13 August 2012

SSIS expression to generate date usable in file names

I finally cracked how to generate the date in an SSIS package in the ISO format of YYYYMMDDHHMM. By including this in file names, e.g. when archiving, it keeps them in logical order when sorted.

Here's the magic expression part:

SUBSTRING( REPLACE( REPLACE( REPLACE( (DT_WSTR, 30)GETDATE(), "-", ""), ":", ""), " ", ""), 1, 12 )

This will produce 201208131830 at 18:30 on 13/Aug/2012. The final 12 in the expression is used to chop it down to the minute. Use 14 if you need it down to the second.

No comments:

Post a Comment