将纪元时间戳转换为 sql server(人类可读格式) [英] converting Epoch timestamp to sql server(human readable format)
问题描述
我在将 Unix 时间戳转换为 sql server 时间戳时遇到问题.
I have a problem in converting the Unix timestamp to sql server timestamp.
我在 Excel 表中有一个数据,我将通过工具导入该数据.所以我正在寻找一种代码或语法,可以将 Epoch 时间戳转换为 sql server 时间戳.
I have a data in excel sheet and I will import that data through a tool. So I am looking for a code or syntax which can convert that Epoch timestamp to sql server timestamp.
我有 3 个具有相同格式的不同列.如何更改这些列中的值.
I have 3 different columns with the same format. How can I change the values in those columns.
例如:
- 纪元时间戳---1291388960
- sql server 时间戳--- 2010-12-03 15:09:20.000
推荐答案
我有 3 个具有相同格式的不同列.如何更改这些列中的值.
I have 3 different columns with the same format. How can I change the values in those columns.
要更新表中的 3 列,您可以将 DATEADD 秒与纪元(1970 年 1 月 1 日)与列名配对,即
To update 3 columns in a table, you can pair DATEADD seconds to the epoch (1 Jan 1970) with the column name, i.e.
update tbl set
datetimecol1 = dateadd(s, epochcol1, '19700101'),
datetimecol2 = dateadd(s, epochcol2, '19700101'),
datetimecol3 = dateadd(s, epochcol3, '19700101')
您无法就地更新,因为 bigint 列不能同时是日期时间列.您必须将它们更新为另外 3 个列.
You can't update in place since a bigint column cannot also be a datetime column. You have to update them into 3 other columns.
这篇关于将纪元时间戳转换为 sql server(人类可读格式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!