Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - converting 13 digit numeric to datetime

How can I convert a 13 digit numeric like 1314637182953 to datetime in SQL Server? Both casting and converting directly give an arithmetic overflow error!

Same result with the query below:

select Convert(datetime, cast(START_DATE as varchar(8)), 112), * 
from table
like image 545
legendofawesomeness Avatar asked Feb 23 '23 02:02

legendofawesomeness


1 Answers

Assuming it's UNIX time in milliseconds, try this:

DATEADD(SECOND, START_DATE/1000 ,'1970/1/1')

For the number from your post, SQL-2008 returns 2011-08-29 16:59:42.000

like image 127
Sergey Kalinichenko Avatar answered Mar 21 '23 08:03

Sergey Kalinichenko