Can i serialized datetime data JSON in query SQL S

2019-09-06 14:35发布

I have deserialize data date time, and save it in my database table column:

\/Date(1328029200000+0700)\/

But can I convert it to date format again using query sql?

1条回答
成全新的幸福
2楼-- · 2019-09-06 15:03
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
查看更多
登录 后发表回答