简体   繁体   English

从csv文件到SQL Server日期时间的SSIS Unix时间戳

[英]SSIS Unix timestamp to SQL Server datetime from csv file

I have tried several options to get this to work but have so far been unsuccessful using the derived column to transform Unix to datetime. 我尝试了几种方法来使它起作用,但到目前为止,使用派生列将Unix转换为日期时间仍未成功。

The column in question is loaded in as a DT_WSTR (I have also tried DT_I4 and DT_I8) and the derived column is then supposed to create the new column with the datetime. 有问题的列作为DT_WSTR加载(我也尝试过DT_I4和DT_I8),然后派生的列应该以datetime创建新列。

This is what i currently have: 这是我目前拥有的:

DATEADD("ss", (dt_i4)[logged_date], (dt_date)("1970-01-01"))

When I try to execute i get an error at the derived column which just states 当我尝试执行时,我在派生列上看到一个错误

"An error has occurred while evaluating the function" “评估函数时发生错误”

Any help would be appreciated. 任何帮助,将不胜感激。

If your Timestamp is in seconds 如果您的时间戳以秒为单位

Select dateadd(SS,1476444566,'1970-01-01') Returns 2016-10-14 11:29:26.000

If micro-seconds (requires a little more workd( 如果是微秒(需要更多工作量(

Declare @UnixTime bigint = 1470562081943371
Select DateAdd(MS,round(((@UnixTime/1000000.)-(@UnixTime/1000000))*1000,0),DateAdd(SECOND,(@UnixTime/1000000),'1970-01-01 00:00:00'))

Found my problem. 发现我的问题。

Turns out there was a row with a null valued unix date which is why SSIS was having a problem with the conversion. 原来有一行的unix日期为空,这就是SSIS转换出现问题的原因。

I have set up an error output to place into an excel file should it happen again. 我设置了错误输出,如果再次发生,将其放置到excel文件中。

Code is now working as expected. 代码现在按预期工作。

Appreciate the help that was offered. 感谢提供的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM