用 T-SQL 中的时间偏移量解析日期时间 [英] Parse date time with time offset in T-SQL
本文介绍了用 T-SQL 中的时间偏移量解析日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下形式的日期(文本):2016-07-05T13:09:35-06:00
I have dates in a following form (text):
2016-07-05T13:09:35-06:00
它是 ODBC 格式,所以我可以简单地:
It's ODBC format, so I was able to simply:
SELECT CONVERT(DateTime2, REPLACE(LEFT(TimeModifiedUnparsed, 19), 'T', ' '), 120)
这就是我 DateTime2
,但没有时间偏移.我可以解析和转换 Hour 和 Minute 和 Sign out of last 6 个字符,然后执行 DATEADD..
但我想也许有更好的方法将这样的字符串转换为 SQL Server 中的 utc DateTime?
That get's me DateTime2
, but without time offset.
I can parse and convert Hour and Minute and Sign out of last 6 characters and then do DATEADD..
but I thought maybe there is a better way to convert such a strings to utc DateTime in SQL Server?
推荐答案
select convert(datetime2, cast('2016-07-05T13:09:35-06:00' as datetimeoffset), 1)
结果:
2016-07-05 19:09:35.0000000
这篇关于用 T-SQL 中的时间偏移量解析日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文