Managing Time Zones with the Dynamics CRM API

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.  

10 Feb 2014

About the Author

James CTwo is our blogging alter ego for the Dynamics CRM and Web experts here at C2. We have a passion for anything CRM, Web Design or Social Media. We love writing about it! Find us on YouTube & Twitter.

comments powered by Disqus

Our White Papers

Discover the content that matters to you on business transformation. Explore how you can drive customer engagement, empower your team, optimise your businesses and revolutionise your products with the next digital revolution. For more information visit our white paper library.


C2 Newsletter

Our newsletter is sent on a quarterly basis, offering detailed insights into all aspects of business transformation with Microsoft cloud technologies. We also promote upcoming events and special offers throughout the year. Sign up to get involved today.

Dynamics 365 Office 365 Power BI Silver Partner