Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved in your SSC briefcase from the favorites tab.
Download now (direct download link)

UDF_GetGMTOffset

By Alex M,

Here is an example query that illustrates how to use the function to easily convert to and from UTC/GMT time and the SQL Server's local time.

SELECT GETDATE() AS 'Local Time',
GETUTCDATE() AS 'GMT Time',
DATEADD(HOUR, dbo.UDF_GetGMTOffset(), GETUTCDATE()) AS 'GMT Time to Local Time',
DATEADD(HOUR, dbo.UDF_GetGMTOffset() * -1, GETDATE()) AS 'Local Time to GMT Time',
dbo.UDF_GetGMTOffset() AS 'GMT Offset'
Results
Local Time GMT Time GMT Time to Local Time Local Time to GMT Time GMT Offset
2010-11-04 09:45:55.827 2010-11-04 14:45:55.827 2010-11-04 09:45:55.827 2010-11-04 14:45:55.827 -5

Total article views: 546 | Views in the last 30 days: 2
 
Related Articles
FORUM

UDF_GetGMTOffset

Comments posted to this topic are about the item [B]UDF_GetGMTOffset[/B] I see that you've defined @...

FORUM

Cube Localization

SSAS localization

FORUM

local server

no local server

FORUM

local replication

local replication error

FORUM

Processing Cubes Locally

Processing Cubes Locally

Tags
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones