Need to convert from LocalTime in any time zone to UTC time in Dynamics 365? The UtcTimeFromLocalTime request can help you with that. Check this out!

UtcTimeFromLocalTime – A function introduced in Dynamics 365 to allow you to convert time in any timezone to the corresponding UTC time. It has couple of parameters

  • LocalTime – DateTime object to set the local time
  • TimeZoneCode – Timezonecode of type integer.

So let’s see how we can put this in action

Advertisements

UtcTimeFromLocalTimeRequest request = new UtcTimeFromLocalTimeRequest();
        request.LocalTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified);
          request.TimeZoneCode = 190; // this is the timezone code IST

 

         UtcTimeFromLocalTimeResponse response = (UtcTimeFromLocalTimeResponse)service.Execute(request);
          var utcDateTime = response.UtcTime;

 

Advertisements

Observe how I have passed the LocalTime value. Please note that if you want to pass the current date time object, don’t use DateTime.Now as it may give undesirable results. Pass the datetime value using DateTIme.SpecifyKind as done in the above code.

If you want to pass some specific date time you can construct a datetime object like below.

request.LocalTime = new DateTime(2020,5,29,21,30,0);

Advertisements

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Notes Manager (https://debajmecrm.com/2019/02/28/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

 

 

 

Published by

Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s