Setting Date-Only Fields in Dynamics 365 with Local Time Using N52 Formulas
Introduction
When working with date-only fields in Dynamics 365, displaying the correct local time can be a challenge. By default, Dynamics 365 stores DateTime fields in Coordinated Universal Time (UTC). This article explains how to set a date-only field to display the local time using N52 formulas.
The Challenge with UTC Date
When using ToString(UtcDateTime(), 'MM/dd/yyyy')
, the date-only field will display the date in UTC when viewed from the Dynamics 365 user interface. For users in different time zones, this can lead to incorrect date values.
Solution: Using LocalTimeFromUtcTime()
The function LocalTimeFromUtcTime()
can convert UTC time to local time. Here's how you can set a date-only type field, "Delivered On," to the current local date:
N52 formulaToString(LocalTimeFromUtcTime(UtcDateTime()), 'MM/dd/yyyy')
When you use this formula, the "Delivered On" field will show the date in local time, as per the time zone settings of the Dynamics 365 user interface.
Conclusion
Understanding time zones and date fields in Dynamics 365 can be complex, but with the right formula, you can ensure the date-only field displays the correct local time. Using LocalTimeFromUtcTime()
in your N52 formula will allow the field to display the date according to the user's local time settings, solving the challenge posed by UTC dates.
No comments:
Post a Comment