Converting Date and Time based on User Time Zone in PowerApp for Dynamics 365 CE

By | March 26, 2019

Introduction

In our previous blog we have explored on how to set date and time fields of dynamics 365 through power app. Handling date and time fields according to time zone is quite tedious task. In today’s blog we will explore more on how to handle date and time fields of dynamics 365 according to user time zone in power apps.

The time zone of dynamics 365 instance is set as “Eastern Time” as shown in below screenshot:

Converting Date and Time based on User Time Zone in Power App for Dynamics 365 CE

But my app is running on the phone where time zone is set as “Indian Standard Time”.

Therefore, we cannot set correct time in the date and time fields due to time zone difference between dynamics 365 and powerapp.

To solve this difference, follow the below steps for updating the date and time fields of records in dynamics 365 through power app:

1. Create a default Canvas app for appointment entity by using Dynamics 365. You can refer our previous blog here

2. Now add “Start Date” and “End Date” fields on the edit screen as shown in the below screenshot:

Converting Date and Time based on User Time Zone in Power App for Dynamics 365 CE

3. Now on “onSelect” property of “IconAccept
Converting Date and Time based on User Time Zone in Power App for Dynamics 365 CEadd patch formula as given below:

Patch(

Appointments,

First(

Filter(

Appointments,

activityid = BrowseGallery1.Selected.activityid

)

),

{

scheduledstart: If(

IsBlank(DateValue1.SelectedDate),

Blank(),

DateAdd(

DateValue1.SelectedDate + Time(

Value(HourValue1.Selected.Value),

Value(MinuteValue1.Selected.Value),

0

),

TimeZoneOffset(),

Minutes

)

),

scheduledend: If(

IsBlank(DateValue2.SelectedDate),

Blank(),

DateAdd(

DateValue2.SelectedDate + Time(

Value(HourValue2.Selected.Value),

Value(MinuteValue2.Selected.Value),

0

),

TimeZoneOffset(),

Minutes

)

)

}

)

Converting Date and Time based on User Time Zone in Power App for Dynamics 365 CE

In the above formula we have implemented the “DateAdd” and “TimeZoneOffSet()” function to convert the data and time value into UTC format.

  • DataAdd: The DateAddfunction adds a number of units to a date/time value.
  • TimeZoneOffSet : The TimeZoneOffsetfunction returns difference between the user’s local time and UTC in minutes.

4. Let’s run the app and set “Start Time” and “End Time” for a record in CRM through PowerApp by selecting Converting Date and Time based on User Time Zone in Power App for Dynamics 365 CE in powerApp.

Converting Date and Time based on User Time Zone in Power App for Dynamics 365 CE

5. Now as shown below the “Start Time” and “End Time” values are updated in CRM in Eastern Time:

Converting Date and Time based on User Time Zone in Power App for Dynamics 365 CE

Conclusion

PowerApps allows user to handle date and time fields of dynamics 365 according to user time zone.

https://www.inogic.com/product/productivity-pack/click-2-clone-microsoft-dynamics-crm-records

 

Leave a Reply

Your email address will not be published. Required fields are marked *