我可以在查询SQL Server 2008中序列化日期时间数据JSON吗 [英] Can i serialized datetime data JSON in query SQL Server 2008

查看:277
本文介绍了我可以在查询SQL Server 2008中序列化日期时间数据JSON吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经反序列化了数据日期时间,并将其保存在我的数据库表列中:

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

\/日期(1328029200000 + 0700)\/

\/Date(1328029200000+0700)\/

但是我可以使用查询sql再次将其转换为日期格式吗?

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

推荐答案

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

这篇关于我可以在查询SQL Server 2008中序列化日期时间数据JSON吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆