web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Issue: Dealing with Datetime in API

(0) ShareShare
ReportReport
Posted on by

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?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Is CRM online or on Premises? If it is online you should know that local time is not your personal local time but that of server where is the plugin executed.

  • Suggested answer
    Community Member Profile Picture
    on at

    It seems this is the same issue I am experiencing. My date fields are timezoneindependent

    What happened to me is that when I create the entity and send in a date, by default the datetimekind is set to local, thus when the SDK creates the entity is going to convert the timezone to the server "local" time.

    Then when you do the retrieve you are getting the datetime that was converted, this only happens to the users that are on a different timezone that the server.

    Now if you set the datetimekind to Utc then crm is not going to do any conversions and your times are going to be left as is.

    Hope this helps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans