Articles in this section
Category / Section

How to Convert DateTime to UTC in Bold Reports

Published:
Updated:

When building applications for users across various regions, accurate time zone management is essential for consistent data representation. In Bold Reports, you can convert local DateTime values to UTC using a custom VB.NET function within the report.

This guide provides step-by-step instructions to implement the UTC conversion function and update report fields for precise time handling.

Solution

Use a custom VB.NET function in Bold Reports Designer to convert DateTimeOffset values to UTC, ensuring standardized time representation across all time zones.

Implementation Steps

Follow these steps to configure UTC conversion in Bold Reports:

  1. Add a Custom UTC Conversion Function

    • Open your report in Bold Reports Designer.
    • Go to Report Properties and click the Code tab.
    • Paste the following VB.NET function into the code editor:
    Public Function ConvertToUTC(ByVal transactionDate As DateTimeOffset) As DateTime
        Return transactionDate.UtcDateTime
    End Function
    

    Adding UTC Conversion Function

The ConvertToUTC function uses the UtcDateTime property to convert DateTimeOffset values to their UTC equivalent, ensuring consistent time zone handling.

  1. Update Report Expressions

    • Identify report fields, groupings, or sorting expressions that use DateTime values.
    • Replace them with the UTC-converted expression using the custom function:
    =Code.ConvertToUTC(Fields!DateTime.Value)
    

    Updating Report Expressions

  • Replace DateTime with the actual field name from your dataset (e.g., Fields!TransactionDate.Value).
  • Apply the expression to all relevant fields, including those used in groupings, sorting, or display.
  1. Save and Preview the Report

    • Save the report after applying the changes.
    • Click Preview button in Bold Reports Designer to view the report in the Report Viewer.
    • Verify that all date/time values display in UTC, consistent across different user time zones.

    Previewing the Report

Additional Guidance

  • Data Source Compatibility: Ensure your dataset’s DateTime field is in DateTimeOffset format. If not, adjust the data source or use additional expressions to handle conversions.

  • Testing Across Regions: Test the report with users in different time zones to confirm consistent UTC output.

  • Error Handling: If the DateTimeOffset conversion fails (e.g., due to invalid data), add error-checking logic to the VB.NET function, such as:

    Public Function ConvertToUTC(ByVal transactionDate As Object) As DateTime
        If TypeOf transactionDate Is DateTimeOffset Then
            Return CType(transactionDate, DateTimeOffset).UtcDateTime
        Else
            Return DateTime.UtcNow
        End If
    End Function
    
  • Performance Considerations: For large datasets, minimize the use of complex expressions across multiple fields to optimize report rendering.

Conclusion

By implementing the ConvertToUTC function and updating report expressions, you can ensure consistent UTC-based time representation in Bold Reports, enhancing reliability for global users.

See Also

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied