Back to Blog Listing
Microsoft Dynamics CRM supports multiple time zones, ensuring that activities and actions are correctly sequenced, regardless of where they occur. This is a real strength of the product, but it is something that needs to be carefully considered when a returning a date and time from the API.
Automatically Adjusted to UTC
When records are saved to the CRM database they are automatically adjusted to UTC - Coordinated Universal Time. This time zone is the same as GMT, but for the UK this will not be adjusted to account for British Summer Time. One of the main issues that developers run into when using the API for the first time is that when you read the data back out of the database using the API, the date and time will not be adjusted to the CRM user's time zone.
For example when UTC(-1) a value added to the CRM as "04/02/2014 00:00" is returned from the API with a value of "03/02/2014 23:00". This is due to the -1 in the UTC being added to the date returned. If you are interested in the date part then you now have a record that is 1 day out.
Reading the Date / Time Adjusted to the User's Time Zone
To address this ensure that you add .tolocaltime to the end of your return statement and this should ensure that the time is returned after being adjusted to the time zone of the CRM user.
EventStartDate = e.new_StartDateandTime.Value.ToLocalTime
You will also need to ensure that the CRM user account that you are using for the API call has the correct timezone set in the personal options settings in CRM.