sql server - How to calculate the local datetime from a utc datetime in tsql (sql 2005)? -
I have to loop in TSLL over a period of time, and print UTC datatoms and our local version. We live in UTC +1, so I could easily add 1 hour, but in the summer we live in UTC +2.
In C #, I can make a datetime and use a method to ask for the UTC version. And vice versa
So far I have this:.
declared @counter declared @localdate datetime declared @utcdate datetime @counter set int = 0 while @counter & lt; 100 @counter set start = @counter + 1 + print cast (@counter as four) set @utcdate = DATEADD is 'counter' (day, @ counter, GETUTCDATE ()) --set @localdate = ???? After the print @localdate print @utcdate end
Assume that you use SQL 2005 On the up side, you can do the development of the SQL CLR function to convert a UTC date and convert it to a local date.
How is an MSDN, to explain how you can create scalar UDF in C #. Create a SQL function on the pattern of
[SqlFunction ()] Public static SqlDateTime ConvertUtcToLocal (SqlDateTime utcDate) {// You to convert SqlDateTime to date time
Your sample will be made up then
set @localdate = dbo .ConvertUtcToLocal (@utcdate)
In case of deployment on SQL CLR, its overheads May include, but me sits just fit it best it seems
Comments
Post a Comment