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

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

Convert a given date to GMT

By James Travis,

In SQL 7 you had no way to convert local time to GMT (UTC time) which was added in SQL 2K as GETUTCDATE() which will output the current date you would get with GETDATE() but a it's GMT counterpart. Although this was a great improvement I work with data on another server that's front end application stores dates as number of seconds since 1/1/1970 GMT. As this is one of the major indexes I really wanted to take advantage of this to pull the data. I also wanted to right this once and be able to reuse over and over. So I wrote a stored procedure to make the conversion from the user input data passed from another procedure accessed from my front end apps. The stored procedure can take any inserted date and convert it to the proper GMT date for that time by taking into account the time of year (the only exception is 1AM to 2AM the last Sunday in October when we fall back and thus it could be either or and I did not put a bit in as my needs did not warrant. This can be easily modified to do so or return the number of seconds instead of date format by making the adjust where each is noted.

Total article views: 561 | Views in the last 30 days: 2
 
Related Articles
SCRIPT

Nested Stored Procedure

Nested Stored Procedure

FORUM

Store Procedure

Store Procedure

FORUM

stored procedure

stored procedure

FORUM

stored procedures

stored procedures

FORUM

stored procedure for seeding

stored procedure

Tags
miscellaneous    
 
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