When working with Power Automate and SharePoint, managing time zones can be a complex task. Whether you're scheduling tasks, automating workflows, or simply trying to display the correct time on a SharePoint list, handling time zones correctly is crucial for ensuring your data is accurate and your workflows run smoothly. In this blog, we'll explore common challenges and provide step-by-step solutions to effectively manage time zones in Power Automate.
Understanding the Time Zone Challenge
SharePoint stores date and time values in Coordinated Universal Time (UTC). While this is great for consistency, it can cause issues when users in different time zones access the data. For example, a task due at 5 PM UTC will display differently for users in New York, London, and Tokyo. Power Automate, being a versatile tool, provides sever always to handle these discrepancies.
Step-by-Step Guide to Handling Time Zones in Power Automate
Step 1: Capture the Time Zone
First, it's essential to capture the user's time zone. This can be done in various ways, such as setting Regional Settings from Site Administration in Site Settings.
1. Create a SharePoint Site & List for Time Zones:
Create a new Site called "SPDDEMO."
Create a new list in SharePoint called "TimeZone."
Add columns for "User" (Person or Group) , "SatartDateAndTime" (Date Picker), "EndDateAndTime" (Date Picker).
2. Set the TimeZone:
Settings > Site Information > View all site settings > Site Administration > Regional Settings
Set the Time zone & Region accordingly you want.
Step 2: Retrieve the Time Zone in Power Automate
Use Power Automate to retrieve the user's time zone when the workflow runs.
1. Get List Item:
Add a "Get items" action to retrieve the user's time zone from the "TimeZone" list.
Add a "Send Http request to SharePoint" action to retrieve the regional time zone from the " SPDDEMO " site.
Add method GET and Uri as _api/web/regionalSettings/Timezone
2. Get Time Zone:
3. Simplify the output using Parse JSON
Pass the above output Body through Parse JSON to get simplify output.
4. Change the sign of Bias:
Use one compose and called “Compose SPDDEMOBias”.
To Change the Bias received from the Parse JSON multiply it with -1(Minus one)
Use function: mul(body('Parse_JSON_SPDDEMO_Regional_Time_Setting')?['d']?['Information']?['Bias'],-1)
Step 3: Convert UTC to the User's Time Zone
Convert the UTC time to the user's time zone in Power Automate using simple add Minutes function and Bias.
1. Add a Compose Action:
Add addMinutes function and the Bias as to be added minutes and then format ‘M/dd/yyyy h:mm tt’ to the get list items in “TimeZone” list like “StartDateAndTime” , “EndDateAndTime”,” Created”, “Modified” etc.
Use function: addMinutes(outputs('Get_item_SPDDEMO')?['body/Created'],outputs('Compose_SPDDEMO_Bias'),'M/dd/yyyy h:mm tt')