SSIS 2008 - Get Current Date in Variables

2020-02-14 10:51发布

问题:

In SSIS 2012 I can get current date using GETDATE() function with expression in variables.

Though, in SSIS 2008 expression fields does not exist.

Question: How can I get current date dynamically with variables in SSIS 2008?

回答1:

Help me understand how GETDATE() doesn't exist in the SSIS Expression language for 2008.

That said, I find that using the system variable @[System::StartTime] preferable to GET_DATE(). StartTime provides a consistent point in time for the duration of a package. It will always be whenever the package begins execution. Contrast that with the value of GETDATE() which is right now. Now. NOW. Every time you inspect that value, it's subject to change. This can cause trouble you when you build a file name with second precision. Or if you want to group all the data that was inserted in a single run. You'll have drift in those values so you must use range queries to identify all the data in run X. Or you can use StartTime which is updated when the package begins to run but remains constant for the duration.



回答2:

Try this:

RIGHT( "00"+ (DT_WSTR, 2) DAY(GETDATE()),2)+RIGHT( "00"+ (DT_WSTR, 2) 
MONTH(GETDATE()),2)+(DT_WSTR, 4) YEAR(GETDATE())