locked
CRM 2011 stores Date Time UTC Kind in database mechanics RRS feed

  • Question

  • Hi everyone,

    I got in trouble with DateTime value. After searching and testing for awhile. This is what I got:

    My environment: CRM 2011 On-Premise update rollup 8.

    1. Date Time value A with Unspecified or Local Kind (input by web GUI or OrganizationService) is converted to Date Time value B with UTC Kind and stored in database.

        a. When user view that Date Time value using web GUI, CRM will convert it to Local time and show it (users see value A).

        b. When user retrieved that Date Time value using OrganizationService, CRM will return DateTime value in database with UTC Kind (developers see value B).

    2. Date Time value C with UTC Kind (specified using code  and input by OrganizationService) is just stored in database.

        a. When user view that Date Time value using web GUI, CRM does nothing, just shown it (users see value C).

        b. When user retrieved that Date Time value using OrganizationService, CRM will return DateTime value in database with UTC Kind (developers also see value C).

    So what I ask is:

    1. Is it correct? If not, please correct it for me.

    2. It is the same in CRM 2011 Online? in Plugin context and Web Service which using OrganizationService?

    --> I have a practice:

    1. When input Date Time value using OrganizationService --> just let it in Unspecified Kind and let CRM do the rest (convert it into UTC Kind, the same as in web GUI).

    2. When retrieved a Date Time value using OrganizationService --> remember to use DateTime.ToLocalTime() when I need to compare it with my own Date Time.

    Do you think it's good? Please recommend me with better practice.

    Any recommend is welcome.

    Thanks.

    Thursday, July 5, 2012 7:51 AM

Answers

  • Hi,

    CRM stores all Data time values in UTC and returns DateTime object with DateTimeKind.UTC. Its us to the consumer (developer) to convert it to local time. Also when submitting the information to CRM if DateTime is local then CRM will convert the datetime to UTC before being storing it. On the CRM UI depending on the user setting the datetime is converted to localtime zone of the user. 

    Hope this helps.


    -Devashish
    http://thecrmworld.wordpress.com
    http://ebizartisans.com

    • Marked as answer by Linh Giang Saturday, July 7, 2012 3:14 AM
    Thursday, July 5, 2012 10:24 AM

All replies

  • Hi,

    CRM stores all Data time values in UTC and returns DateTime object with DateTimeKind.UTC. Its us to the consumer (developer) to convert it to local time. Also when submitting the information to CRM if DateTime is local then CRM will convert the datetime to UTC before being storing it. On the CRM UI depending on the user setting the datetime is converted to localtime zone of the user. 

    Hope this helps.


    -Devashish
    http://thecrmworld.wordpress.com
    http://ebizartisans.com

    • Marked as answer by Linh Giang Saturday, July 7, 2012 3:14 AM
    Thursday, July 5, 2012 10:24 AM
  • Thanks for your reply.

    By saying "On the CRM UI depending on the user setting the datetime is converted to localtime zone of the user". It's true that if I set my IE option to location A I will see date time value A', and if I change to location B, I'll see value B'????

    Thanks

    Friday, July 6, 2012 4:56 AM