Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What DateTime is returned from Dynamics CRM API

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);
}
like image 831
GER Avatar asked Jun 29 '16 16:06

GER


2 Answers

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.

like image 102
Henrik H Avatar answered Oct 13 '22 01:10

Henrik H


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

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

like image 2
pinginrua Avatar answered Oct 13 '22 00:10

pinginrua