Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

converting Epoch timestamp to sql server(human readable format)

I have a problem in converting the Unix timestamp to sql server timestamp.

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.

I have 3 different columns with the same format. How can I change the values in those columns.

For Example:

  • Epoch timestamp ---1291388960
  • sql server timestamp--- 2010-12-03 15:09:20.000
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have 3 different columns with the same format. How can I change the values in those columns.

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')

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...