About Me

My photo
Mumbai, Maharastra, India
He has more than 7.6 years of experience in the software development. He has spent most of the times in web/desktop application development. He has sound knowledge in various database concepts. You can reach him at viki.keshari@gmail.com https://www.linkedin.com/in/vikrammahapatra/ https://twitter.com/VikramMahapatra http://www.facebook.com/viki.keshari

Search This Blog

Thursday, December 19, 2013

SQL Server 2008 new Datatime function SWITCHOFFSET


Returns a datetimeoffset value that is changed from the stored time zone offset to a specified new time zone offset. It also change the given time to the offset passed as parameter unlike TODATETIMEOFFSET

 SWITCHOFFSET ( DATETIMEOFFSET, time_zone )

Lets do some query to understand this

select sysdatetimeoffset() as Current_Time_With_OffsetValue

Current_Time_With_OffsetValue
----------------------------------
2013-12-18 23:16:46.0192745 +05:30

So the current time with offset is 2013-12-18 23:16:46.0192745 +05:30

Let’s apply SWITCHOFFSET to check what we will get

select switchoffset(sysdatetimeoffset(),'-04:00') as Changed_Time
Changed_Time
----------------------------------
2013-12-18 13:53:16.7063393 -04:00

Here we can see the current time and zone changed to 13:53:16.7063393 -04:00

Let’s take one few more example

select switchoffset(sysdatetimeoffset(),'+04:00') as Changed_Time
Changed_Time
----------------------------------
2013-12-18 21:55:38.6735346 +04:00

The current time and zone changed to 21:55:38.6735346 +04:00


Switchoffset :It does not only change the offset. It also changes the time with the appropriate time at Time zone specified in offset. I will take both this in deeper view in coming article.

Set off jogging with your logic and carry out an elegant and community will call it mastery code.

Post Reference: Vikram Aristocratic Elfin Share

No comments:

Post a Comment