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.
2007-10-02 (first published: 2002-06-20)
15,451 reads