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:
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:
3. Now on “onSelect” property of “IconAccept”
add patch formula as given below:
activityid = BrowseGallery1.Selected.activityid
DateValue1.SelectedDate + Time(
DateValue2.SelectedDate + Time(
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 in powerApp.
5. Now as shown below the “Start Time” and “End Time” values are updated in CRM in Eastern Time:
PowerApps allows user to handle date and time fields of dynamics 365 according to user time zone.