-1

I have a number like this 1628864262422 and I wish to to convert it to datetime in SQL Server. How do I do this?

Thank you

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • 1
    And explain how that number should be translated into a date i.e. what should the result of that value be? And note, a datetime datatype does not have a display format (hence why I removed it from your question). – Dale K Sep 23 '21 at 03:39
  • 1
    Does this answer your question? [UNIX\_TIMESTAMP in SQL Server](https://stackoverflow.com/questions/8837225/unix-timestamp-in-sql-server) – Charlieface Sep 23 '21 at 04:12
  • And what datetime would that be? There are literally dozens of different used "epochs" for numerical date/time values. An example of some of them: https://en.wikipedia.org/wiki/Epoch_(computing). – Gordon Linoff Sep 23 '21 at 11:43

1 Answers1

3

If you don't care about the MS, you can try

Select dateadd(SECOND,1628864262422/1000,'1970-01-01')

Results

2021-08-13 14:17:42.000
John Cappelletti
  • 79,615
  • 7
  • 44
  • 66
  • That's gorgeous man, You're a life saver. Can you briefly explain to me like why do we add '1970-01-01' at the end ? i mean how do you know why we have to add that specific date? – Nam Nguyen Sep 23 '21 at 03:10
  • 1
    @NamNguyen I just assumed a UNIX time stamp take a peek at https://www.unixtimestamp.com/index.php – John Cappelletti Sep 23 '21 at 03:41