问题
I want to calculate last friday's date in ssis. Below code is doing it.
DATEADD("dd", -1 - (DATEPART("dw", getdate()) % 7), getdate())
But it gives results for datetime datatype and I want results for int data type in ssis.
How to convert?
DATEADD("dd", -1 - (DATEPART("dw", getdate()) % 7), getdate())
回答1:
According to this Microsoft article:
When a string is cast to a DT_DATE, or vice versa, the locale of the transformation is used. However, the date is in the ISO format of YYYY-MM-DD, regardless of whether the locale preference uses the ISO format.
In order to convert value to integer yyyyMMdd
,
- First you have to convert the value to a string
- Get the first 10 digit
- Remove the
-
separator - Convert to integer.
You can use the following expression:
(DT_I4)REPLACE(SUBSTRING((DT_WSTR,50)DATEADD("dd", -1 - (DATEPART("dw", getdate()) % 7), getdate()),1,10),"-","")
来源:https://stackoverflow.com/questions/56550831/convert-ssis-expression-datetime-to-int