If you’ve got your dates and datetimes stored as UTC in your database, but want to show the local time value on your reports in SQL Reporting Services, there is a simple solution for this!
Change the expression for the filed to the code below :
=System.TimeZone.CurrentTimeZone.ToLocalTime(Fields!DateTime.Value)
This converts your UTC datetime field to the local time zone value.




2 comments ↓
That works well inside a corporate database, or a controlled environment, but what about a global web application? Are there any tricks you can provide on the database end that will help programmers who can’t stand working with timezones? I was led to believe, by less knowledgeable people that you just through everything into the database as UTC and perform calculations after you pull the information out of the database.
Your only option, really, is to either
1. get the IP address and attempt to guess the timezone based on the lookup
2. ask the user to provide their timezone and store the offset for future calculations in their user/profile records
Time zones are completely a pain in the ass, but generally storing in UTC is about your only option, and your friends were 100% right that you have to include that logic in pretty much everything you do if you’re working on a global application.
In my case most of this work spans a few continents and we have many stored procedures, functions, and assemblies to handle this work for us. It sucks, and I forget to do it a lot.
You must log in to post a comment.