Wednesday, 22 June 2011

CRM 2011 - DateTime issues.

If you've used the DateTime values within CRM 2011 you'd know that they are no longer the CrmDateTime types CRM 4.0 used.  They use the nullable type DateTime?. Where issues have occurred is assuming that CRM will convert the date stored in the value within the database to the users Time Zone/Locale when returning the value through the SOAP/OData services.  As it currently stands it will return the value as UTC time and thus if you had used the value directly the time WILL be out, unless of course your local time is UTC time. 

There are a number of ways around this but simplest and my recommendation is to use the DateTime.ToLocal() method. This will user the server time for plugins and custom workflow activities, and will use the local users time for SilverLight applications.  This should work for 90% of all situations as it fits into the standard CRM development model.


NOTE: When saving a DateTime value CRM will convert the value to UTC time so you do not need to worry about conversions.

No comments:

Post a Comment