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)
 Convert UTC to local PC time

Author  Topic 

harlingtonthewizard
Constraint Violating Yak Guru

352 Posts

Posted - 2009-02-05 : 01:13:30
DateTime fields stored in our DB are in UTC. The problem is that when reports are run I need to convert the displayed time to current TimeZone and Daylight savings for the respective PC. Does anyone have a function to do this effectively. I found some functions they claim to have issues during the daylight saving hour etc.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-05 : 01:16:40
Search the forum for udf_timezone_conversion. It does not have issues with daylight saving time conversions, but it will need to be updated for the new DST rules as I never reposted the newer version here as I'm no longer the author of it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

harlingtonthewizard
Constraint Violating Yak Guru

352 Posts

Posted - 2009-02-05 : 02:00:23
This function looks like it only works with United States or some hard coded place? I dont know the country of installation so it needs to read the time zone from the PC. For example if on my PC (the sql server) the time was UTC 12:00pm as stored in a field and I did a query from Adelaide, Australia then the time would be 21:30 for display.
Go to Top of Page

harlingtonthewizard
Constraint Violating Yak Guru

352 Posts

Posted - 2009-02-05 : 02:16:59
This link here looks promising however the stored proc and udf are missing, only the C# code is present. Anyone used this and have all the code?

http://channel9.msdn.com/playground/Sandbox/139123/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-05 : 11:02:06
The function supports lots of timezones and not just the United States. In one of the posts where I posted the function, you'll find the rows that need to get added to the Timezone table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

harlingtonthewizard
Constraint Violating Yak Guru

352 Posts

Posted - 2009-02-05 : 18:28:24
I am using this now and it seems to work well. Thanks tkizer for your help and the credit for this one goes to Mike Dimmick and William Stacey [MVP] for the end solution.

http://channel9.msdn.com/playground/Sandbox/139123/

My mistake all the code is there just need to install the assembly and set permissions. Code supports:
UTC to Local.
Local to UTC.
Any time to Any Time.
Supports Windows DST tables so no need to worry about that nasty daylight savings.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-05 : 19:26:49
Cool glad you found a solution. I haven't touched udf_timezone_conversion in quite some time, although I know we are using it production with some changes due to the new DST rules. I think I'll recommend what you found to my projects.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -