In sql server, the value = 20171030131152 exists in the database as start-time and 20171030131236 as end-time. I want to convert it into date time so that I can calculate elapsed time between start-time and end-time. Below is the code I tried to convert it start-time into datetime declare @starttime nvarchar(255) = '20171030131152' select CAST(@starttime as datetime)