Search code examples
sql-serverreporting-servicesvisual-studio-2019sql-server-data-toolsdate-formatting

SSRS - Format datetimeoffset value from SQL


I am creating a report in SSRS 2019, and the SQL query for my main dataset is pulling a value that is type datetimeoffset. In the column where this value is displayed, the customer does not wish to see the raw value, but instead "dd MMM yyyy hh:mm tt" format. I have tried the following expression as the value for this column:

=FORMAT(Fields!myDateValue.Value, "dd MMM yyyy hh:mm tt")

However, when I run this report, even though every row is guaranteed to have a value, the column populates as #Error. I tested the expression with a datetime value instead, and that worked properly, but the customer wants the value passed through as datetimeoffset. I am also able to format the value as a string in SQL correctly, but they want it done as a expression in the report table. What must I do to accomplish this expression without causing an error on the column?


Solution

  • What you want is this expression (or something similar to get the exact format you need):

    =DateTime.Parse(Fields!myDateValue.Value.ToString).ToUniversalTime