Converting normal datetime to a time zone in sql server 2008

浪子不回头ぞ 提交于 2019-12-23 18:53:40

问题


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

for example

2007-05-08 12:35:29.1234567 +05:30 (GMT)

回答1:


Cast it to dtaetimeoffset like

select CAST(dt as datetimeoffset)  from test

EDIT:

you can then use SWITCHOFFSET to get into the specified timezone. For your example

select switchoffset(CAST(dt as datetimeoffset),'+05:30')  from test 

Results in 2011-11-24 23:26:30.0600000 +05:30



来源:https://stackoverflow.com/questions/8256892/converting-normal-datetime-to-a-time-zone-in-sql-server-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!