Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Posso serializar dados de data e hora JSON na consulta SQL Server 2008

declare @jsondate varchar(40) = '\/Date(1328029200000+0700)\/';
select substring(@jsondate,8,10) -- seconds
      ,substring(@jsondate,18,3) -- milliseconds
      ,substring(@jsondate,21,5) -- utc offset
      ,
-- this next expression is what you need
       cast(convert(char(20),
       dateadd(ms,1*substring(@jsondate,18,3),
       dateadd(ss,1*substring(@jsondate,8,10),'19700101'))
        ,120) + stuff(substring(@jsondate,21,5),4,0,':')
            as datetimeoffset(4));

-- result 2012-01-31 17:00:00.0000 +07:00