没有DateAdd()的SSIS表达式以前的日期 [英] SSIS expression previous date without DateAdd()
问题描述
当前正在开发一个程序包,该程序包将前一个日期的表达式传递到文件名。我拥有的当前代码如下所示:
Currently developing a package that passes an expression from a previous date to a filename. The current code I have is the following as a string variable:
(DT_WSTR,20)DATEPART( YYYY,Dateadd( DD ,-1,dateadd( MM,datediff( MM,
(DT_DATE) 1900-01-01,getdate())-2,(DT_DATE) 1900-01-01) ))
+ RIGHT( 0 +(DT_WSTR,20)DATEPART( MM,Dateadd( DD,-1,dateadd( MM,datediff( MM,(DT_DATE) 1900 -01-01,getdate())-5,(DT_DATE) 1900-01-01)))),2)
+ 01
(DT_WSTR,20)DATEPART("YYYY",Dateadd("DD",-1,dateadd("MM",datediff("MM", (DT_DATE) "1900-01-01",getdate())-2, (DT_DATE) "1900-01-01"))) + RIGHT("0"+(DT_WSTR,20)DATEPART("MM",Dateadd("DD",-1,dateadd("MM",datediff("MM", (DT_DATE) "1900-01-01",getdate())-5, (DT_DATE) "1900-01-01"))),2) + "01"
当前生成的输出为:
20171101
20171101
当前这是不正确的,因为我希望该日期为上一年:
This is currently incorrect because I'd like the date to be from the previous year:
20161101
20161101
这里是我想要的论坛:
返回从今天起过去7个月的月份的第一天。
Return the 1st day of the month that is 7 months in the past from today's date.
例如:5/2/2017将返回11/1/2017; 2017年6月21日将返回2016年12月1日; 2017年7月10日将返回1/1/2017;等等。
Example: 5/2/2017 would return 11/1/2017; 6/21/2017 would return 12/1/2016; 7/10/2017 would return 1/1/2017; etc.
可以通过SSIS中的变量来做到吗?
Is this possible to do via a variable in SSIS?
推荐答案
您的表达式可以对此进行修改(并简化)
Your expression can be modified (and simplified) to this
(DT_WSTR, 8)( ( YEAR( DATEADD( "MM", -7, GETDATE() ) ) * 10000 ) + ( MONTH( DATEADD("MM", -7, GETDATE() ) ) * 100 ) + 1 )
- 从当前日期减去7个月
- 将结果年份乘以10000
- 从当前日期起减去7个月
- 将结果月份乘以100
- 将年值,月值和1相加(第一天)
- 转换为字符串
- subtract 7 months from current date
- multiply resulting year by 10000
- subtract 7 months from current date
- multiply resulting month by 100
- add year-value, month-value and 1 (first day)
- convert to string
在在SSIS包中的昨天日期设置为@Rangani,通过表达式在变量中设置,以表示乘以并添加而不是字符串concat
Credit to @Rangani in Yesterday's date in SSIS package setting in variable through expression for "multiply and add instead of string concat" trick
这篇关于没有DateAdd()的SSIS表达式以前的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!