how to convert a date into both European and American time zones in the same sql server report rdl?

StackOverflow https://stackoverflow.com/questions/20716348

Domanda

I have a report which takes timezone as input parameter, picks date from a table and converts this date to the user selected time zone. User can select timezones from a dropdown which contains both US and European timezones. When I select the European timezones, I see #Error in the date cell in the report. I have no clue what so ever about reports and I need to fix this error in the inherited report.

The conversion is done by a little VB script embedded in the report.

Shared Function ConvertTimeZone(ByVal systemDate As Date, ByVal timeZoneId As String) As Date
    Dim timeZoneInfo As TimeZoneInfo
    timeZoneInfo = timeZoneInfo.FindSystemTimeZoneById(timeZoneId)           
    Return (timeZoneInfo.ConvertTimeFromUtc(systemDate, timeZoneInfo))
End Function

If EET is passed as timezone id - I see #Error in the date cell. Could this be because both European and US timezones cant be used together?

Can someone guide me through this issue?

È stato utile?

Soluzione

If EET is passed as timezone id - I see #Error in the date cell

That's because "EET" is not a valid time zone identifier. You can see all of the valid identifiers by examining the output from TimeZoneInfo.GetSystemTimeZones(), which returns a collection of TimeZoneInfo objects. Each one has an Id and a DisplayName. The Id is what needs to be passed in your timeZoneId parameter, while the DisplayName can be shown to your end user in the dropdown list. (You probably don't want to use the StandardName or DaylightName properties, unless you have a specific reason to.)

You are probably looking for the identifier "E. Europe Standard Time". Don't get confused by the name, it's the correct identifier covering both Eastern European Time (EET) and Eastern European Summer Time (EEST). The Microsoft time zone database is a bit strange in that way.

You can also see the valid time zones by running tzutil /l on the command line. Each time zone will emit two lines, where the top line is the display name, and the bottom line is the ID.

EDIT

Another suggestion, VB is case insensitive, but you have your variable named timeZoneInfo, which is the same as the class TimeZoneInfo. This would normally work ok, but I see that you have the lower case form on the ConvertTimeFromUtc method, and it should be upper case. Since this is VBScript, you might not be seeing this error until runtime. Try changing the case, or just use a different variable name so you don't get them confused.

Shared Function ConvertTimeZone(ByVal systemDate As Date, ByVal timeZoneId As String) As Date
    Dim tzi As TimeZoneInfo
    tzi = timeZoneInfo.FindSystemTimeZoneById(timeZoneId)           
    Return (TimeZoneInfo.ConvertTimeFromUtc(systemDate, tzi))
End Function

Here's another idea you can check if that doesn't fix it. The input systemDate should have come from your data, which should have DateTimeKind.Unspecified when you examine it's .Kind property. If for some reason you are taking it from DateTime.Now instead, then it would have a DateTimeKind.Local, which would through an exception.

If you still get the error, please see if you can find out what exception or error is actually occurring. Check log files, event viewer, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top