如何使用SQL从不同的美国时区转换为IST? [英] How to convert from different US Time Zones to IST using SQL?

查看:209
本文介绍了如何使用SQL从不同的美国时区转换为IST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在中有一个数据一个SQL DataTable by 名称DPSDateTime。下面显示的数据列是,其中值为:





crea_date Disp_Day Disp_Time State TimeZone

11/13/14 5:56 PM 2014年12月18日星期四19:00:09 IL(GMT-06:00)中部时间(美国和加拿大)

11/24/14 11:17 AM 2014年12月24日星期三10:27:44西澳大利亚州(格林威治标准时间-07:00)山区时间(美国和加拿大)

12/12 / 14 1:19 PM 2014年12月24日星期三19:24:33 WI(格林威治标准时间-06:00)中部时间(美国和加拿大)

12/13/14 12:05 PM 2014年12月25日星期四12:36:27加州东部时间(格林威治标准时间-05:00)(美国和加拿大)

12/17/14 11:33 AM 2014年12月29日(星期一) 08:16:35 OR(GMT-08:00)太平洋时间(美国和加拿大);蒂华纳

12/17/14 2:03 PM 2014年12月25日星期四13:00:21加州(格林威治标准时间05:00)美国东部时间(美国和加拿大)

12/18/14 11:05 AM 2014年12月25日星期四15:06:44 TX(格林威治标准时间-06:00)中部时间(美国和加拿大)

12/18 / 14 9:16 AM 2014年12月25日星期四07:59:16 WA(格林威治标准时间-07:00)山区时间(美国和加拿大)

12/18/14 5:27 PM星期六,2014年12月20日11:23:04西澳大利亚州(格林威治标准时间-07:00)山区时间(美国和加拿大)

12/19/14 10:07 AM 2014年12月29日星期一06:55:31洛杉矶(格林威治标准时间-06:00)中部时间(美国和加拿大)

12/22/14 2014年12月22日下午4:44 18:20:27新泽西州(格林尼治标准时间-05:00)东部时间(美国和加拿大)

12/22/14 2014年12月22日星期一下午4:53 17:47:08 OK(格林威治标准时间-06:00) )中部时间(美国和加拿大)

12/23/14 1:31 PM星期五,12月26日,2014 18:37:00 NH(格林威治标准时间-05:00)东部时间(美国和美国加拿大)

12/23/14 3:18 PM 2014年12月23日星期二21:25:26 MS(GMT-06:00)中部时间(美国和加拿大)

12/23/14 4:37 PM 2014年12月26日星期五15:28:04 MD(GMT-05:00)东部时间(美国和加拿大)



  上面的 crae_date 具有 DateTime 状态 TimeZone列显示相应的Sate  TimeZones  值< span class =code-keyword> in  crea_date  column 

我希望 添加另一个 名称ISTTime。我希望 显示 crea_date 转换为 IST(印度标准时间





提前致谢。

解决方案

以下是时区之间转换的示例:



到中部时区的IST

  select  cast(switchoffset(todatetimeoffset(GETDATE(),'  + 05:30'),'   -  06 :00' as   datetime  as  日期时间 





IST的中心时区

 选择 cast(switchoffset(todatetimeoffset(GETDATE( ),'   -  06:00'),'  + 05:30' as   datetime  as   DateTime  


< blockquote>这将从2014年19:00:09返回-06:00 IL(GMT-06:00)

  SELECT  SUBSTRING(disp_time,CHARINDEX('  GMT',disp_time)+ 3, 6 





将此日期时间偏移用于最终查询(假设King Fishers + 5:30是对的):

  SELECT  CAST(SWITCHOFFSET(TODATETIMEOFFSET(cre a_date,SUBSTRING(disp_time,CHARINDEX('  GMT',disp_time)+ 3, 6 ),'  + 05:30' as   datetime 







如果这有帮助,请花时间接受解决方案。谢谢。


Hi,

I have the Data in a an SQL DataTable by the name DPSDateTime. Shown below are the data columns with values:



crea_date Disp_Day Disp_Time State TimeZone
11/13/14 5:56 PM Thursday, December 18, 2014 19:00:09 IL (GMT-06:00) Central Time (US & Canada)
11/24/14 11:17 AM Wednesday, December 24, 2014 10:27:44 WA (GMT-07:00) Mountain Time (US & Canada)
12/12/14 1:19 PM Wednesday, December 24, 2014 19:24:33 WI (GMT-06:00) Central Time (US & Canada)
12/13/14 12:05 PM Thursday, December 25, 2014 12:36:27 CA (GMT-05:00) Eastern Time (US & Canada)
12/17/14 11:33 AM Monday, December 29, 2014 08:16:35 OR (GMT-08:00) Pacific Time (US & Canada); Tijuana
12/17/14 2:03 PM Thursday, December 25, 2014 13:00:21 CA (GMT-05:00) Eastern Time (US & Canada)
12/18/14 11:05 AM Thursday, December 25, 2014 15:06:44 TX (GMT-06:00) Central Time (US & Canada)
12/18/14 9:16 AM Thursday, December 25, 2014 07:59:16 WA (GMT-07:00) Mountain Time (US & Canada)
12/18/14 5:27 PM Saturday, December 20, 2014 11:23:04 WA (GMT-07:00) Mountain Time (US & Canada)
12/19/14 10:07 AM Monday, December 29, 2014 06:55:31 LA (GMT-06:00) Central Time (US & Canada)
12/22/14 4:44 PM Monday, December 22, 2014 18:20:27 NJ (GMT-05:00) Eastern Time (US & Canada)
12/22/14 4:53 PM Monday, December 22, 2014 17:47:08 OK (GMT-06:00) Central Time (US & Canada)
12/23/14 1:31 PM Friday, December 26, 2014 18:37:00 NH (GMT-05:00) Eastern Time (US & Canada)
12/23/14 3:18 PM Tuesday, December 23, 2014 21:25:26 MS (GMT-06:00) Central Time (US & Canada)
12/23/14 4:37 PM Friday, December 26, 2014 15:28:04 MD (GMT-05:00) Eastern Time (US & Canada)

In the above table crae_date column has DateTime Value and State and TimeZone Columns show the respective Sate and TimeZones for the value in crea_date column.

I want to add another Column by the Name ISTTime. I want to show the value of the crea_date column converted into IST (Indian Standard Time) in this column.



Thanks in advance.

解决方案

Here is the Example for Convert Between the Time Zones :

IST to Central Time Zone

select cast(switchoffset(todatetimeoffset(GETDATE(), '+05:30'), '-06:00') as datetime) as DateTime



Central Time Zone to IST

select cast(switchoffset(todatetimeoffset(GETDATE(), '-06:00'), '+05:30') as datetime)as DateTime


This will return -06:00 from 2014 19:00:09 IL (GMT-06:00)

SELECT SUBSTRING(disp_time, CHARINDEX('GMT', disp_time)+3, 6)



Using this for datetime offset gives final query (assuming King Fishers +5:30 is right):

SELECT CAST(SWITCHOFFSET(TODATETIMEOFFSET(crea_date, SUBSTRING(disp_time, CHARINDEX('GMT', disp_time)+3, 6), '+05:30') as datetime )




If this helps please take time to accept the solution. Thank you.


这篇关于如何使用SQL从不同的美国时区转换为IST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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