Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
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)

SQL
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.
Posted
Updated 12-Jan-15 0:30am
v2
Comments
Sinisa Hajnal 12-Jan-15 6:04am    
Parse your disp_time, take time difference from GMT, add your time difference and add the total to crae_time via DateAdd function.
ZohaibRazaTheDProgrammer 12-Jan-15 6:27am    
@Sinisa Hanjal

Thanks for your quick response. It would be very helpful if you could post a meaningful SQL QUERY to achieve what you have mentioned in your response (viz. Parse your disp_time, take time difference from GMT, add your time difference and add the total to crae_time via DateAdd function).

Thanks in Advance.

Here is the Example for Convert Between the Time Zones :

IST to Central Time Zone
SQL
select cast(switchoffset(todatetimeoffset(GETDATE(), '+05:30'), '-06:00') as datetime) as DateTime


Central Time Zone to IST
SQL
select cast(switchoffset(todatetimeoffset(GETDATE(), '-06:00'), '+05:30') as datetime)as DateTime
 
Share this answer
 
This will return -06:00 from 2014 19:00:09 IL (GMT-06:00)
SQL
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):
SQL
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900