Tuesday, November 9, 2010

SSIS Get date with the leading zeros

Hello,

Just a quick note on formatting SSIS date expression to display leading zeros for single digits days and months.

With refeence to this article ... http://codingstuffs.blogspot.com/2007/03/pgp-inside-ssis-package.html

The mentioned date variable can be done in a different way..

(DT_WSTR,4)YEAR(GETDATE()) +
SUBSTRING("0" +   (DT_STR, 2, 1252) DATEPART( "MM", GETDATE()) , LEN( "0" +   (DT_STR, 2, 1252) DATEPART( "MM", GETDATE()) ) - 1, 2 ) +
SUBSTRING("0" +   (DT_STR, 2, 1252) DATEPART( "DD", GETDATE()) , LEN( "0" +   (DT_STR, 2, 1252) DATEPART( "DD", GETDATE()) ) - 1, 2 )


or even using a smaller expression

Right( "0" + (DT_WSTR, 2 ) MONTH(Getdate()),2)  + "-" +
Right( "0" + (DT_WSTR, 2 ) DAY(Getdate()),2)  + "-" +
(DT_WSTR,4)YEAR(GETDATE())

Hope that helps.