- Yes, the only time the
DateTime
is local in CRM is when you are creating a newDateTime
in code, and not specifying that it's UTC, or when it is displayed to the user. Anytime CRM stores a `DateTime, if it isn't specified as UTC, it will convert it to UTC based on the user's TimeZone. - Since the SDK is returning it as UTC keep it in that format. Just be aware that if you create a new
DateTime
, you have to specify that it is UTC (DateTime to UTC ), or else the SDK will convert it to UDC when you save or update it. - This is moot if you always work in UTC.
CRM EarlyBoundEntities DateTime
-
03-12-2021 - |
سؤال
I have a Dynamics CRM system that works across multiple timezones. The users work in their local timezones and I have some services that interact with the entities they create.
All code is done through the SDK Generated early bound entity classes.
For example:
- User creates a record with an associated task start and end date in GMT-4 timezone
- Start Date through UI = 2012/11/23 00:00:00
- Start Date in DB = 2012/11/22 20:00:00
- End Date through UI = 2012/11/25 00:00:00
- End Date in DB = 2012/11/24 20:00:00
- Services process that record and create a task with start and end dates - this time the service account is at GMT+1 (BST)
- Start Date through Code = 2012/11/22 20:00:00
- Start Date in DB = 2012/11/22 19:00:00
- End Date through UI = 2012/11/24 20:00:00
- End Date in DB = 2012/11/24 19:00:00
- User looks at created record and sees the task start and end dates are 4 hrs earlier - which when the UI renders it shows as 2012/11/22 23:00:00 where the user was expecting 2012/11/23 00:00:00.
I am seeing issues where when a user creates a record which is used by the services that the date mismatch is causing issues.
So I guess I have a number of questions:
- Is the datetime returned by the SDK EarlyBoundEntities in Local or UTC (I suspect UTC)?
- If its in UTC should my code that updates/creates records also convert the datetime I work on to UTC before setting it (i.e. use datetime.ToLocal() when getting and ToUTC() when setting)?
- Should my server adjust for daylight savings or should it stay at a set time i.e. UTC?
المحلول
لا تنتمي إلى StackOverflow