在sql server 2008中将正常datetime转换为时区 [英] Converting normal datetime to a time zone in sql server 2008
本文介绍了在sql server 2008中将正常datetime转换为时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 datetime
数据类型的列。它包含很少的条目。因此,当从select语句获取值时,我想使用时区输出。请帮助我
I have a column which is of datetime
data type. It contains few entries. So while getting the value from the select statement I want to output with Time zone. Please help me
例如
2007-05-08 12:35:29.1234567 +05:30 (GMT)
推荐答案
将它转换为 dtaetimeoffset
like
Cast it to dtaetimeoffset
like
select CAST(dt as datetimeoffset) from test
编辑:
使用 SWITCHOFFSET
进入指定的时区。对于您的示例
you can then use SWITCHOFFSET
to get into the specified timezone. For your example
select switchoffset(CAST(dt as datetimeoffset),'+05:30') from test
结果 2011-11-24 23:26:30.0600000 +05:30
这篇关于在sql server 2008中将正常datetime转换为时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文