This article will walk you through some scenarios regarding setting date fields when using the CreateRecord() & UpdateRecord() functions.
- Dynamics 365 stores all date \ datetime fields in the database in UTC timezone
- When using the functions CreateRecord() or UpdateRecord() it is always assumed that the incoming date is in the UTC timezone.
- For the purposes of this article we will assume the user has their timezone set to "GMT -05:00 Eastern Time". This can be found under the user settings within Dynamics 365.
Example 1 :
UpdateRecord('contact', [contact.contactid], SetAttribute('birthdate', UtcDateTime()) )
-The UtcDateTime() function returns the current date & time for the UTC timezone so this could be "2013-Jan-10 18:23:45". It is this datetime which will be stored in the database.
-As the user is in a timezone -5 hours on UTC time the user will see in the Birth Date field on the form the following datetime, "2013-Jan-10 13:23:45". Notice a completely different time.
Example 2 :
UpdateRecord('contact', [contact.contactid], SetAttribute('birthdate', UtcDate()) )
-The UtcDate() function returns the current date for the UTC timezone & always sets the time component to midnight. so this could be "2013-Jan-10 12:00:00". It is this datetime which will be stored in the database.
-As the user is in a timezone -5 hours on UTC time the user will see in the Birth Date field on the form the following datetime, "2013-Jan-09 19:23:45". Notice a completely different date and time.
In most cases it is best to use UtcDateTime() when you need to set a date field to today.
Date & Time settings can be tricky to understand within Dynamics 365. If you really want to get up to speed on how they work please read this excellent article from Scott Durow of Ribbon WorkBench fame.
Did you know?
North52 helps streamline complex healthcare processes
Healthcare providers are no strangers to complex processes and rules. Patients expect efficient and seamless service.
The North52 business rules engine helps healthcare providers implement complex rules in their Dynamics 365 systems quickly and without code. The rules are easily modified, tested and deployed as regulations and requirements change.