5

Are the DateTime objects returned from the Dynamics CRM web API always in UTC and where is that documented?

I am using the CRM SDK nuget package. I've read on several blogs (by CRM shops) that the CRM API always returns UTC DateTime objects and I have experienced that the DateTime.Kind is always UTC (from my testing) but I need to know for sure.

The CRM is 2015 if that matters.

I am calling a Dynamics CRM web services with the following code.

 var querybyattribute = new QueryByAttribute()
 {
     EntityName = Opportunity.EntityLogicalName,
     ColumnSet = new ColumnSet(true)//all columns
 };

querybyattribute.Attributes.AddRange(attributeName);
querybyattribute.Values.AddRange(attributeValue);

And then calling RetreiveMultiple

EntityCollection entities;
using (var proxy = new ManagedTokenOrganizationServiceProxy(serviceManagement, credentials))
{
    entities = proxy.RetrieveMultiple(query);
}
Tim Hutchison
  • 2,865
  • 5
  • 33
  • 67
GER
  • 1,500
  • 3
  • 20
  • 27

2 Answers2

5

There are three different types of behavior for dates in CRM. Only two of them truly have the concept of timezone. The behavior of the three types can be found on MSDN, with the relevant parts copied here:

UserLocal (this is the only one available in CRM 2015 pre Update 1)

The retrieve operation returns the UTC value.

DateOnly

For the retrieve and update operations, no time zone conversion is performed, and the time value is always 12 AM (00:00:00).

TimeZoneIndependent

For the retrieve and update operations, no time zone conversion is performed, and actual date and time values are returned and updated respectively in the system regardless of the user time zone.

Henrik H
  • 5,597
  • 1
  • 19
  • 33
  • So the behaviors are applied to every date field. I would need to examine the metadata and figure out which behavior the field has and then figure out if conversion is necessary. – GER Jun 29 '16 at 16:42
2

"In Web services (SDK), these values are returned using a common UTC time zone format. "

https://technet.microsoft.com/en-us/library/dn946904.aspx

pinginrua
  • 21
  • 4