有没有更好的方法来解析 SSIS 中的 [Integer].[Integer] 样式日期?

Is there a better way to parse [Integer].[Integer] style dates in SSIS?

我正在处理一个 SSIS ELT 脚本,该脚本需要从以 [INTEGER].[INTEGER] 格式存储的 TSV 文件中解析日期(Excel integer dates 后跟自午夜以来的第二个,例如 42825.94097;或自午夜以来的微秒数,例如 42831.1229166667)。我想出了以下方法:

  1. 派生列函数将输入拆分为日期部分和时间部分
  2. Derived Column 函数将解析的日期附加在一起,例如,

    DATEADD("day",StartTime_Date,DATEADD("second",StartTime_Time,(DT_DATE)"1/1/1900"))
    

有没有更优雅的方式来做到这一点而不诉诸脚本组件?

The DT_DATE data type is implemented using an 8-byte floating-point number. Days are represented by whole number increments, starting with 30 December 1899, and midnight as time zero. Hour values are expressed as the absolute value of the fractional part of the number. However, a floating point value cannot represent all real values; therefore, there are limits on the range of dates that can be presented in DT_DATE." Read more

从上面的描述可以看出,在将这些值转换为 8 字节浮点数后,将它们映射到 DT_DATE 列时,可以隐式转换这些值 DT_R8.

使用派生列转换将此列转换为 8 字节浮点数:

(DT_R8)[dateColumn]

然后将其映射到 DT_DATE

或者施放两次:

(DT_DATE)(DT_R8)[dateColumn]

实验

我用一个 DataFlow Task

创建了一个 SSIS 包

DataFlow 任务包含一个脚本组件(作为源)生成一个输出行(一列类型 DT_R8),值为 42825.94097.

脚本组件链接到派生列,派生列使用以下表达式

将此列转换为DT_DATE
(DT_DATE)[Column]

我得到的输出如下图

相关回答

关于这个问题我有很多答案:

  • SSIS Error importing Excel Date (truncation error)