问题描述
我们将所有日期SQL Server 2008数据库以UTC时间的形式存储在DateTime列中。
我正在使用SSRS来创建报告,我需要将报告中的所有时间都转换到运行报告的计算机的时区。
$ b $我知道可以随时将当前的时区偏移作为参数传递给报表,并从时区添加或减去偏移量,但由于夏令时,这不会正确显示历史日期。
SSRS是否有任何处理此功能的功能?我应该将时区传递给SQL Server函数,并让SQL Server转换时间?
我想出来了。
在SSRS报告中,我添加了一个对程序集的引用System.Core
然后我需要转换我使用的时区:
= Code.FromUTC(Fields!UTCDateFromDatabase.Value,Parameters!TimeZone.Value)
其中参数!TimeZone.Value是可以通过使用TimeZone.CurrentTimeZone.StandardName
可以在应用程序中检索的时区的字符串值我应该放在FromUTC中:
共享函数FromUTC(ByVal d As Date,ByVal tz As String)As Date
返回(TimeZoneInfo.ConvertTimeBySystemTimeZoneId(d,TimeZoneInfo.Utc。 Id,tz))
end function
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 the Time Zone of the computer where they're running the report from.
I know could always just pass in the current timezone offset as a parameter to the report and add or subtract the offset from the timezone, but this wouldn't correctly show historical dates because of daylight savings.
Does SSRS have any functions that handle this? Should I pass the timezone to the SQL server functions and have the SQL Server convert the time?
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
这篇关于在SSRS中使用时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!