I'm trying to format a datestamp to have leading zeros in an expression using SSIS 2008 R2.
My desired result would be Exceptions - YYYYMMDDHHMMSS.xls
so as an example, now would be:
\\SomePath\Exceptions - 20150211155745.xls
I am having an issue adding the leading zeros to the day and month though.
I've tried the following expressions by trying to convert to DT_WSTR
with the length set as well as picking the date apart usg SUBSTRING
:
@[User::XLFileRootDir] + "Exceptions - " + (DT_WSTR, 4) DATEPART("YYYY", GETDATE()) + (DT_WSTR, 2) DATEPART("MM", GETDATE()) + (DT_WSTR, 2) DATEPART("DD", GETDATE()) + ".xls"
This results in \\SomePath\Exceptions - 2015211155745.xls
(notice the missing leading zero on the month).
@[User::XLFileRootDir] + "Exceptions - " + (DT_WSTR, 4) SUBSTRING(GETDATE(), 1, 4) + ".xls"
This results in an error as the data type DT_DBTIMESTAMP
isn't supported by the function SUBSTRING
. I'm aware that some sort of conversion needs to take place but can't find a function within SSIS to complete this.
Could anyone help me with how to format the expression with leading zeros?