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)

SDK/C# Timezone offset applied twice when saving a local time into a datetime field on CRM online.

(0) ShareShare
ReportReport
Posted on by

I made a very simple program to demonstrate the problem as simply as possible to myself, and eliminate as many variable as possible.

it connects to Crm with a given user, lets say: bob 

bob's timezone is set to CET (currently 2+ offset from UTC as its summer time)

my own computer, where the program runs is also set to CET.

My program does the following:

  • as bob, it retrieve a entity
  • it fills a datefield on the entity like so: entitie["datefield"] = DateTime.now 
  • update entity back to CRM.
  • and retrieve entity again from CRM and checks the date (the raw UTC value, not the formatted one) 

The date is now not the expected 2 hours behind local time, but 4 hours.

The value displayed to the user is therefor 2 hours behind what's expected.

  • Changing bobs timezone in CRM to +4 (Baku) and running the program again:

results in 6 hours offset instead of 2

  • Setting my computer timezone to +8 (Beijing):

Results in a offset of 12 instead of 2.

so it seems to apply both the local computer's offset where the code runs, AND the user's configured timezone's offset!

I can understand it adjusting for either the PC's local time, OR the users timezone, either one would have made at least some sort of sense.

but not both right?

Can anyone help me and explain whats going on? And is there a way to save local time and have it end up correct? (We do this extensively throughout or code it would be a time consuming to adjust it all) 

our on premise installation doesn't have this problem, despite both the user and the server being set to CET.

Crm: (versie 1612 (8.2.2.1259) (DB 8.2.2.339) online)

SKD/DLL version used 8.2.0 (nugets)

(side note: saving the time as entitie["datefield"] = DateTime.UtcNow always gives the correct result.)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    you can take a look on below post, it explains the date and time  behavior in various aspect

    www.powerobjects.com/.../crm-2011-truths-about-datetime

  • Community Member Profile Picture
    on at

    thanks for replying,

    that's one of the links i found myself while researching, unfortunately it says nothing about CRM applying both the local computers timezone as well as the user configured one, at the same time.

    judging by this line, "DateTime set through CRM Web Services is user’s local time zone by default"

    It would seem that it should only adjust for the user configured timezone, and ignore the computers local time. But that's not what's happening.

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    can you share your code here? i will test it on my side

  • Community Member Profile Picture
    on at
    Sure thing, and thank you for taking the time. 


    //boilderplate var credentials = new ClientCredentials(); credentials.UserName.UserName = userName credentials.UserName.Password = Password; string xrmServerUrl = "ourserver.crm4.dynamics.com"; Uri organizationUri = new Uri(string.Format("{0}/XRMServices/2011/Organization.svc", xrmServerUrl)); var organizationService = new OrganizationServiceProxy(organizationUri, null, credentials, null); organizationService .EnableProxyTypes(); //boilderplate //get entity var entity = organizationService.Retrieve("entityLogicalName", new Guid("C2EA1587-0731-E811-813F-00DC2967EB29"), new ColumnSet(true)); //set date field entity["datefield"] = DateTime.Now; //update organizationService.Update(entity); //retrieve updated entity, entity = organizationService.Retrieve("entityLogicalName", new Guid("C2EA1587-0731-E811-813F-00DC2967EB29"), new ColumnSet(true));
    //read the date
    var date = (DateTime)entity["datefield"];


    with both the user's timezone in CRM and the computer running the code set  to CET (2+ in summer time)

    and i do this at 16:00,

    i would expect the date at the end to contain a UTC datetime of 14:00

    but it's actually 12:00!

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    can you show me the datefield setting in CRM ?

  • Community Member Profile Picture
    on at

    sure, it's in Dutch so i'll have to translate.

    required: optional

    searchable: yes,

    fields security: disabled

    checks: disabled

    interactive: both not checked)

    datatype: date and time

    fieldtype: simple

    behavior: usersetting

    format: date and time

    IME-modus: inactive

    and there are no business rules defined.

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    sorry for late, in my environment, it is working fine, is the date time setting same as yours?

    2086.7.png

  • Community Member Profile Picture
    on at

    Thanks for the video, couldn't be clearer, and that's the behavior i would expect. And in fact what i get on our on-premise environments. but not online. all 3 our online instances show the same behavior.

    That's so weird!

    The only differences in the date time settings are that auditing is disabled and IME mode is set to inactive.

    Neither one of which should have any effect on this that i can tell.

    At the very least i now know its something on our end and not normal Crm online behaviour.

    Tomorrow i'll see if i can try a different tenant/organisation and try the program from a different computer,

    and i'll try to update the SDK files as well.

    Thank you for the help so far, i'll keep you posted on the results.

  • Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Hi Vincent,

    For DateTime, I suggest you to always use DateTime.UtcNow instead of DateTime.Now. It will eliminates problem with different region.

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    is your online tenant under different regions ?

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