3

Using Postman, or the C# program I have, I am trying to send a date to CRM. The date being passed is "2019-09-15", but when it shows up in CRM it is "2019-09-14".

In Postman, I am sending this in the PATCH body:

{
  "org_paymentreceived": "2019-09-15"
}

In the C# program, I am sending this:

{
  "org_paymentreceived": Convert.ToDateTime(payment)
}

In both cases, it is quite clear 2019-09-15 is being passed, but still shows up as 2019-09-14 in CRM.

cjones
  • 8,384
  • 17
  • 81
  • 175

4 Answers4

1

Dynamics CRM always stores as UTC in backend Datetime field, so whenever you are creating Datetime attribute make sure to set the behavior like timezone independent as you wish or user-local by default.

Otherwise, set the right timezone settings under personal options of that particular user account used for web api interactions as same as your user base.

The local datetime passed to CRM will be converted into UTC & stored. Then on retrieval reverse engineering is done.

CRM UI will render the current login user timezone based value in that datetime field. Whereas any SDK, web api call will fetch the UTC value as it is from database.

1

Building on @Arun Vinoth's answer...

Here's how I handle passing UTC into D365 in C#:

public class XrmDate
{
    public DateTime Now() => DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc);        
}

usage:

myEntity["myDate"] = new XrmDate().Now();
Aron
  • 3,877
  • 3
  • 14
  • 21
1

You can also define the behavior of date time attributes to translate the time automatically or not when creating or updating a field.

You can disable the "Dynamics automatically calculates dates for you based on your local timezone" by simply disabling it on field level. So you don't need to cast it to UTC time if it is not important to your instance (for example if you only work in one timezone).

Draken
  • 3,134
  • 13
  • 34
  • 54
Sir Kato
  • 151
  • 1
  • 4
0

I had that problem with retrieving datetime from CRM by web api. Fortunatelly formated values has correct date.

Banana Cake
  • 1,172
  • 1
  • 12
  • 31