Handle time zone correctly in Power Automate

Consider the situation where Power Automate retrieves a date time value from Dataverse and incorrectly specifies the value as a day before the correct date. (As a result of not handling the time zone correctly). This post describes an example of how to configure Dynamics 365 and Power automate in order to avoid this issue

Issue

1.) Within Dynamics 356, specify the format on the Agreement Date column as ‘Date Only’ (Figure 1)

Figure 1

2.) Select the ‘Agreement Date’ value (Figure 2). (Note: Dynamics 365 is configured for the timezone of GMT+11hrs)

Figure 2

3.) When the Agreement Date is stored in Dataverse, it’s stored as GMT+0hrs (Figure 3)

Figure 3

4.) When the Agreement Date is read into Power Automate, it’s incorrectly set to the previous day (Figure 4)

Figure 4

Solution

1.) Set the format for the field as ‘Date and Time’ (Figure 5)

Figure 5

2.) The time is now also displayed on the form (Figure 6). To hide this, add the following JavaScript to the form on load event

FormContext.getControl(“<publisher>_agreementdate”).setShowTime(false);

Figure 6

3.) When the Agreement Date is read in Power Automate, it now displays the time as well (Figure 7)

Figure 7

4.) The Agreement Date is then converted from GMT+0hrs to GMT+11hrs (1 extra hour for daylight savings) (Figure 8)

Figure 8

5.) The date now correctly displays within Power Automate (Figure 9)

Figure 9

Further reading

Power Automate blog posts

References

https://learn.microsoft.com/en-us/power-automate/convert-time-zone