[英]IoT Hub / Stream Analytics - SQL - Convert incoming timestamp to Date Time
I have a timestamp coming in as milliseconds after 01/01/1970 ([timestamp] below is the column name for the data), and need to add an additional column that uses SQL to take these milliseconds and convert it to a date/time format.我有一个时间戳在 01/01/1970 之后以毫秒为单位(下面的 [timestamp] 是数据的列名),并且需要添加一个使用 SQL 的附加列来获取这些毫秒并将其转换为日期/时间格式。
I have attempted:我尝试过:
SELECT DATEADD(MILLISECOND, [timestamp] %1000, DATEADD(SECOND, [timestamp] /1000, '19700101'))
I am getting the error:我收到错误消息:
Cannot cast value '19700101' of type 'nvarchar(max)' to type 'datetime' in expression 'DATEADD ( SECOND, [timestamp] / 1000, '19700101' )'.
无法将类型“nvarchar(max)”的值“19700101”转换为表达式“DATEADD (SECOND, [timestamp] / 1000, '19700101')”中的类型“datetime”。 At line '2' and column '152'.
在“2”行和“152”列。
Any help is appreciated, thank you!任何帮助表示赞赏,谢谢! - M
- 男
You need to specify 19700101
in ISO timestamp format instead, so 1970-01-01T00:00:00Z
您需要以 ISO 时间戳格式指定
19700101
,因此1970-01-01T00:00:00Z
SELECT DATEADD(MILLISECOND, [timestamp] %1000, DATEADD(SECOND, [timestamp] /1000, '1970-01-01T00:00:00Z'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.