Working with Time Zones in SSRS

后端 未结 2 2012
感动是毒
感动是毒 2020-12-13 21:38

We store all our dates SQL Server 2008 database in UTC time in DateTime columns. I\'m using SSRS to create reports and I need to convert all the times on the reports to th

相关标签:
2条回答
  • 2020-12-13 22:04

    I figured it out. In the SSRS report, I've added a reference to the assembly System.Core

    Then anywhere I needed to convert the timezone I used:

    =Code.FromUTC(Fields!UTCDateFromDatabase.Value, Parameters!TimeZone.Value)

    where Parameters!TimeZone.Value is the string value of the timezone which can be retrieved in the application by using TimeZone.CurrentTimeZone.StandardName

    I should probably put what FromUTC does:

    Shared Function FromUTC(ByVal d As Date, ByVal tz As String) As Date
     Return (TimeZoneInfo.ConvertTimeBySystemTimeZoneId(d, TimeZoneInfo.Utc.Id, tz))
    end function
    
    0 讨论(0)
  • 2020-12-13 22:06

    Try using this instead:

    =System.TimeZone.CurrentTimeZone.ToLocalTime(Fields!DateTime.Value)
    

    For SSRS reports called from AX 2012, this is what I use.

    Credit goes to this post: http://social.msdn.microsoft.com/Forums/en-US/500448a3-bf58-44ab-8572-81becd67d8b8/convert-utc-time-to-local-time?forum=sqlreportingservices

    0 讨论(0)
提交回复
热议问题