Use of Switchoffset Function in SQL Server

 

–Creating a test table
CREATE TABLE TB
(
FG DATETIME
)
–Insert an element
INSERT TB
SELECT GETDATE()
SELECT * FROM TB
–convert in to Indian offset time(means +5.30)
SELECT TODATETIMEOFFSET(FG,’+05:30′) DATETIME_OFFSET INTO #TEMP
FROM TB
SELECT * FROM #TEMP
–Convert in to Eastern US Time using Switchoffset
SELECT SWITCHOFFSET(DATETIME_OFFSET,’-04:00′) EASTERN_TIME_US FROM #TEMP

–Creating a test table
CREATE TABLE TB(FG DATETIME)–Insert an elementINSERT TBSELECT GETDATE()
SELECT * FROM TB–convert in to Indian offset time(means +5.30)SELECT TODATETIMEOFFSET(FG,’+05:30′) DATETIME_OFFSET INTO #TEMPFROM TB
SELECT * FROM #TEMP–Convert in to Eastern US Time using SwitchoffsetSELECT SWITCHOFFSET(DATETIME_OFFSET,’-04:00′) EASTERN_TIME_US FROM #TEMP

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.