Set varZones in the Powerapp

Convert your time faster in Power Apps to all time zones using Power Automate

Over the weekend Brian Dang asked me on twitter if there are any easy ways to avoid an apply to each step. He gave me an example where he tried to convert time to other time zones.

So what you do when you want to convert your time to other multiple other time zones?

Well of course this is possible!

The first I will explain the situation that we are trying to solve. In my example I will create a date and time in Power Apps. Then I will l use a button in Power Apps to convert the time to all time zones in the world using a Flow in Power Automate.

I will first show you the end result:

I hope that you will agree that this flow will need to run as fast as possible as we wouldn’t want the user to wait for 30 seconds to do all the work. If we created a flow with an apply to each loop, creating all  the data then you will find that the flow might take a bit longer than you would hope for.  We want a flow that takes nearly no time at all.

This is the flow that I’ve created. From the flow run you can see, 0 seconds! That is good enough for me.

Fast running Flow converting time zones

To understand the above flow you might want to have a look at a couple of posts.

Pushing the time into the Select

I’m going to create a select action that will take the input time. The input time however is text, rather than an array.

  • String as input for select

I will now see the following error when I run my flow:

  • Input variable is string

The create an array, I’m using a variable. Yes I’m aware that variables could slow down my flow, but I’m not going to use any loops therefor it will not make any difference and the data type formatting supplied by variables is helpful in this case.

create the array

 

Convert your time

Now that we have an array I can feed my select action.

  • UTC Format Date

First I will need to format the input date correctly.

format Date In Compose action

In the above action I used the following expression to get this done:

formatDateTime(triggerBody()['Time_Inputs'], 'yyyy-MM-ddThh:mmZ')

Generating all the timezones

My select action will now need to contain a mapping for each time zone.

Select action with time zones

For each mapping, I’m using an expression like this to generate the data

convertFromUtc(item(),'Afghanistan Standard Time')

Returning data to Power Apps

The Respond to a PowerApp or flow action doesn’t support arrays. The response action however does handle arrays.

Returning only the first item

I’m only going to return the first item in the array given by the select as I will only ever receive on item with all time zones that I’ve generated in my Select.

and my flow is ready!

The Power App

Now the easy part.

My Power App takes a date and time form an input field in my app and when I press a button the flow will be kicked off setting a variable called varZones.

Set varZones in the Powerapp

Now I can refer to varZones.whateverzone to get my correct time and date

Getting a zone

 

Concluding thoughts

Quite often building your flows with Apply to each steps can be the easy way to automate your processes, however when you need some performance out of your flow then you might want to consider removing these slow steps. Especcially when you have a user starting a flow and waiting for a response then you don’t want to let them wait forever.

Do you need to get your flows to perform better then please feel free to contact me.

One thought on “Convert your time faster in Power Apps to all time zones using Power Automate

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: