convert ssis expression datetime to int

微笑、不失礼 提交于 2020-01-04 01:51:30

问题


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,

  1. First you have to convert the value to a string
  2. Get the first 10 digit
  3. Remove the - separator
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!