将ssis表达式datetime转换为int [英] convert ssis expression datetime to int

查看:139
本文介绍了将ssis表达式datetime转换为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


  1. 首先,您必须转换值转换为字符串

  2. 获取前10位数字

  3. 删除-分隔符

  4. 转换为整数。

您可以使用以下表达式:

 (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,

  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),"-","")

这篇关于将ssis表达式datetime转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆