2

I'm currently added a text box to my report in which I'd like to add an expression that will do one of two things (either is fine for my purposes).

Either A. Display the local time of the user who ran the report in the text box. B. Display the Eastern Standard Time of when the report was ran.

No matter what I do, the expression only displays the time the report was run in zulu (the server time of SSRS), even if I'm looking at SSRS on the web side signed in from my time zone.

I've tried the following:

=Now()

(displays Server datetime)

=Today()

(displays server date at 12AM still in zulu)

=formatdatetime(today)

(displays only server date, still in zulu)

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

(This says my report is invalid. I says my text box refers to 'datetime', and "Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope.)

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

(same issue as above, except it says my test box is referring to 'UTCDateFromDatabase'. Not sure if I'm missing something from that person's post. They had a Similar Question )

I found one other examples that didn't work that I unfortunately can't find again right now. One which did the same thing as above, only displaying the server datetime (there was mention of 'UTC' in the code).

I can't find anything for how to convert simply to a timezone, and anything that claims to pick up the end user's time zone doesn't seem to work.

Any assistance would be great.

Rally To Me
  • 39
  • 1
  • 8
  • I'd be interested to know if there's a way to display local time as well. I could never find a solution. If you can display it in EST then why not just use `DATEADD(Hour,-5,Now())` in your expression? – BJones Dec 03 '19 at 19:48
  • Even if you could do that, you'd be changing it every 6 months or so with DST. There are SQL Server functions you can use (at time zone) that account for that automatically in the table fields, but they don't work in expression fields. – Rally To Me Dec 03 '19 at 19:51
  • This other question seems to give a couple of solutions to your problem. [Working with Time Zones in SSRS](https://stackoverflow.com/questions/2969689/working-with-time-zones-in-ssrs) – Steve-o169 Dec 03 '19 at 21:24

1 Answers1

1

Perhaps you could try:

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

Courtesy of : https://social.msdn.microsoft.com/Forums/sqlserver/en-US/500448a3-bf58-44ab-8572-81becd67d8b8/convert-utc-time-to-local-time?forum=sqlreportingservices

B. Seberle
  • 370
  • 1
  • 8
  • That will work as long as the time is stored in UTC and the server is in the preferred time zone. – Ross Bush Dec 04 '19 at 13:57
  • 1
    The poster stated that it was the server time he was getting and it was in zulu time. – B. Seberle Dec 04 '19 at 14:13
  • In my post I'd mentioned using a piece of code from 2006, this code you supplied is it. I'll update now it has been found again. If I use this method, it just says my report is invalid. – Rally To Me Dec 04 '19 at 16:11