SSIS 包日期格式

SSIS Package Date format

我在 Azure 中有一个数据工厂,它有一个管道来执行 SSIS 包。此包中包含一个提取脚本,可将日期值从 2019-01-13 00:00:00 转换为 2019-01-13。在此之后,逻辑应用程序选择 extract.txt 文件并将其发送到 sftp 以放入文件夹中。

正如您从我在 SSMS 中的提取脚本中看到的那样,将 varchar 数据类型转换为日期(我在 Unix 中接收日期),对于到达日期,给出了以下值。

脚本

数据查看器

但是当我打开 extract.txt 文件时,日期显示为:2019-01-13 00:00:00.0000000

谁能告诉我为什么他们认为这可能会发生?谢谢

当您将日期列映射到平面文件时,即使它没有出现在数据查看器或 ssms 中,它也会包含时间。

SSIS 解决方案

不在源中使用 dateadd(),而是保留该列,在 SSIS 中使用具有以下表达式的派生列:

LEFT((DT_WSTR,50)DATEADD("s", [start], (DT_DATE)"1970-01-01",10)

输出

2019-01-13

基于Cast (SSIS Expression) official documentation

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.

SQL服务器解决方案

使用以下 SQL 命令:

select convert(varchar(10), dateadd(S, [start], '1970-01-01'),120)