Converting Time zones with Power Automate

If you’ve ever had to convert a timezone with Power Automate then you’re hopefully aware that there is a “Convert Time Zone” action that is designed to make this process easier for you. If you’ve had to convert one time to multiple different time zones all at once then it very quickly becomes a pain to create a Flow as it requires a new action for each conversion.

Did you know that Microsoft supports 250 different time zones? If you wanted to see your local time represented in all of these different time zones all at once then it would be really inefficient to create a Flow for this, so how could we do it?

Note: if you’d like to see how to achieve the same functionality using a Select action instead of an array then read Pieter Veenstra’s excellent post on the topic.

The Solution

If you’ve read any of my recent posts, you’ll be aware that I’m a big fan of arrays, and this is a perfect opportunity to use one. In the Flow below I’m going to create an array of time zones using the data from the table on the Windows Default Time Zones page I linked above, and then I’ll convert the current UTC time to each of those to generate an output.

1. Trigger – for the purposes of this demo I’m using a manual trigger, but you could of course use any trigger that gives you a time and date you want to work with.

2. Initialize ConvertedTimes string variable – we’ll create an empty string variable called ConvertedTimes that we will use to capture the outputs when we loop through the time zones later in the Flow

3. Intialize TimezonesArray array variable – next we’ll create an array variable that we will populate with our array of time zones for conversion. I’ve included an extract of the array below:

[
  {
    "Timezone": "Afghanistan Standard Time",
    "UTC Offset": "(UTC+04:30)",
    "Description": "Kabul",
    "Country": "Afghanistan"
  },
  {
    "Timezone": "FLE Standard Time",
    "UTC Offset": "(UTC+02:00)",
    "Description": "Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius",
    "Country": "Åland Islands"
  },
  {
    "Timezone": "Central Europe Standard Time",
    "UTC Offset": "(UTC+01:00)",
    "Description": "Belgrade, Bratislava, Budapest, Ljubljana, Prague",
    "Country": "Albania"
  },
  {
    "Timezone": "W. Central Africa Standard Time",
    "UTC Offset": "(UTC+01:00)",
    "Description": "West Central Africa",
    "Country": "Algeria"
  }
]

The array contains information on the Time Zone including the name, it’s UTC offset, a description of some of the cities where it has effect, and the country of origin.

The full array is included in the Flow that you can download by clicking the link at the bottom of this post.

4. Parse JSON – next we run a Parse JSON step on the TimezonesArray variable so we can access the array item values for use in our Apply to Each loop. The schema that we use for the Parse JSON step is:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "Timezone": {
                "type": "string"
            },
            "UTC Offset": {
                "type": "string"
            },
            "Description": {
                "type": "string"
            },
            "Country": {
                "type": "string"
            }
        },
        "required": [
            "Timezone",
            "UTC Offset",
            "Description",
            "Country"
        ]
    }
}

5. Apply to Each – we use the Apply to Each condition to loop through each of the time zones from our Time Zones Array. Inside the loop we only have one Append to String Variable action, and we’re using this to convert the time to the Time Zone for the array item and capture the output.

To convert the time zone we use the convertTimeZone expression. As you can see from the reference, the convertTimeZone expression uses the following format:

convertTimeZone(‘<timestamp>’, ‘<sourceTimeZone>’, ‘<destinationTimeZone>’, ‘<format>’?)

I’ve constructed the expression as follows:

convertTimeZone(utcnow(),'UTC',items('Apply_to_each')['Timezone'], 'dd MMMM yyyy hh:mm tt')
  1. timestamp – I’m using the utcNow() expression to get the current date and time, but of course you could pass in any value from your trigger to here
  2. sourceTimeZone – I’ve hardcoded this to be ‘UTC’ in my Flow, but you could get the current User’s timezone in your own scenario to set it dynamically, or set it to any other timezone
  3. destinationTimeZone – for the destination Time Zone I’m using the Time Zone from the current array item, so it will be set dynamically for each time zone
  4. format – I’ve created a custom date format to show me the day, month as a full word, full year, and then the time as a 12 hour display with an AM/PM designation

For the rest of the String I’m also including the Country, UTC Offset and Description from the array for each item, and then including a line break, so the output will look something like:

30 January 2020 06:34 AM Barbados (UTC-04:00) Georgetown, La Paz, Manaus, San Juan

6. Compose – The final step is just a compose step to let me see the output of the Apply to Each loop. Once you have all the times converted you could use them in whatever way you please

Based on the inputs above, the output from the Flow will look something like:

Conclusion

In this flow I wanted to demonstrate how we could take an array of timezone inputs and convert a specified time to all of them in a quick and efficient manner; in my demo I’ve used an array of 250 time zones but the good thing with an approach like this is that it doesn’t matter how many values are in your array.

I realise it’s unlikely that you’d want to convert a time to 250 different time zone values (and I’m also aware that there is crossover between time zones, so there are multiple time zones sharing the same UTC offset), but I’ve worked in organisations that have worldwide operations so it’s always useful to be able to convert deadlines to local times in each office. Similarly, I know that there are lots of virtual events that have attendees from all over the world so it is handy to be able to see the local time for each attendee.

I think this flow could be expanded even further to make it more dynamic, but I hope it has provided some useful food for thought. If you’d like to download it and have a play with it yourself then please click here

Published by

3 thoughts on “Converting Time zones with Power Automate

Leave a comment