Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Converting to UTCDate

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2009-04-25 : 18:37:05
Hi there

I have a stored procedure that passing datetime and inside that procedure I want to convert that into UTCdate cause all records was stored in UTCDate.

How do I do this?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-04-25 : 18:43:44
This will only work for your SQL Server's local timezone:

SET @dateparam=DateAdd(minute, DateDiff(minute, GETUTCDATE(), GETDATE()), @dateparam)

If the procedure accepts values from other timezones you'll have to use the new Datetimeoffset datatype and include the timezone information and then adjust it with the TODATETIMEOFFSET function:

http://technet.microsoft.com/en-us/library/bb630335.aspx
Go to Top of Page
   

- Advertisement -