I'm dealing with importing some records via API in CRM 2016 and detected some strange behaviour.
Because I had some issues related to timezones I did some testing specially focused on the Datetime.Kind-Property. I expected same behaviour for DateTimeKind.Unspecified and Datetime.Local, but both are different - even from DateTimeKind.Utc
I know that Dynamics always returns DateTime in UTC.
The Timezone of the Computer and the User are set to CET/UTC+2
Please see code below:
DateTime unspecified = Convert.ToDateTime("2016-08-18"); DateTime utc = DateTime.SpecifyKind(Convert.ToDateTime("2016-08-18"), DateTimeKind.Utc); DateTime local = DateTime.SpecifyKind(Convert.ToDateTime("2016-08-18"), DateTimeKind.Local); DateTime[] times = { unspecified, utc, local }; foreach (DateTime time in times) { Entity account = new Entity("account"); account["new_datetime"] = time; Guid id = getService().Create(account); Entity responseAccount = getService().Retrieve("account", id, new ColumnSet("new_datetime")); Console.WriteLine("Sent {0:o}", account["new_datetime"]); Console.WriteLine("Received {0:o}", responseAccount["new_datetime"]); }
Output:
Sent 2016-08-18T00:00:00.0000000
Received 2016-08-17T22:00:00.0000000Z
Sent 2016-08-18T00:00:00.0000000Z
Received 2016-08-17T00:00:00.0000000Z
Sent 2016-08-18T00:00:00.0000000+02:00
Received 2016-08-17T20:00:00.0000000Z
Does Dynamics CRM add the +2 of the user ontop of the +2 of timezonelocal?
Or how can I Interpret this results?