将ssis表达式datetime转换为int [英] convert ssis expression datetime to int
问题描述
我想计算上次星期五在SSIS中的日期。下面的代码正在执行此操作。
DATEADD( dd,-1-(DATEPART( dw,getdate()) %7),getdate())
但是它给出了datetime数据类型的结果,我想要int的结果
如何转换?
DATEADD( dd,-1-(DATEPART( dw,getdate())%7),getdate())
根据此 Microsoft文章:
将字符串强制转换为DT_DATE时,反之亦然,使用转换的语言环境。但是,日期是采用YYYY-MM-DD的ISO格式,而不考虑语言环境首选项是否使用ISO格式。
为了将值转换为整数 yyyyMMdd
,
- 首先,您必须转换值转换为字符串
- 获取前10位数字
- 删除
-
分隔符 - 转换为整数。
您可以使用以下表达式:
(DT_I4)REPLACE(SUBSTRING((DT_WSTR,50)DATEADD( dd,-1-(DATEPART( dw,getdate())%7),getdate()),1,10), -,)
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())
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),"-","")
这篇关于将ssis表达式datetime转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!