cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Create an array of dates

Hi all, 

I need to create a an array between two UTC dates. Then i want to be able to get .day of each day and check if it is a weekday or not (so if its a saturday or sunday then do not increment an counter) , then get the ammout of working days between two UTC dates. Is there a way to initialise an empty array and then add dates into it (by incrementing one UTC dates to equal another) ? 

 

Thanks a lot. 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @JasonHough,


It seems that you would like to get the amount of working days between two dates.
Please try with the following workaround.
Add a Button trigger.
Add Compose action for Start date:

utcNow('yyyy-MM-dd')

 

Add Compose 2 for End date:

addDays(utcNow(),6,'yyyy-MM-dd')

 

Initialize variable, set name as IndexDate, Type as String, select dynamic content Output of Compose for Value field.
Initialize variable 2, set Name as DateArray, Type as Array, Value with the following code:

array(outputs('Compose'))

 

Add a Do until action, select variable IndexDate for the left value field, and Output of Compose 2 for the right value field.
Within the Do until loop, add Compose 3 with the following code:

addDays(variables('IndexDate'),1,'yyyy-MM-dd')

Add action Set variable, select name IndexDate, Value set as output of Compose 3.
Add action Append to array variable, Name as DateArray, Value as variable IndexDate.
Under the Do until loop, add Compose 4, select variable DateArray as its Input.
Initialize variable 3, set Name as Weekends, Type as Integer, Value as 0.
Add an Apply to each, select output from variable DateArray.
Within Apply to each, add a Condition to check if it is Saturday or Sunday.

Or
(
dayOfWeek(items('Apply_to_each')) is equal to 6
dayOfWeek(items('Apply_to_each')) is equal to 0
)

Under If yes branch, Increment variable, Name set as weekends, value as 1.
Under the Apply to each, add Compose5, with variable Weekends as its input.
Add Compose6 with the following code to get the total days between the two dates:

length(variables('DateArray'))

Add Compose 7 to get the workdays:

sub(outputs('Compose_6'),variables('Weekends'))

Hope this could be a workaround for you.

1.PNG2.PNG3.PNG4.PNG5.PNG6.PNG 

 

Best regards,
Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
Community Support
Community Support

Hi @JasonHough,


It seems that you would like to get the amount of working days between two dates.
Please try with the following workaround.
Add a Button trigger.
Add Compose action for Start date:

utcNow('yyyy-MM-dd')

 

Add Compose 2 for End date:

addDays(utcNow(),6,'yyyy-MM-dd')

 

Initialize variable, set name as IndexDate, Type as String, select dynamic content Output of Compose for Value field.
Initialize variable 2, set Name as DateArray, Type as Array, Value with the following code:

array(outputs('Compose'))

 

Add a Do until action, select variable IndexDate for the left value field, and Output of Compose 2 for the right value field.
Within the Do until loop, add Compose 3 with the following code:

addDays(variables('IndexDate'),1,'yyyy-MM-dd')

Add action Set variable, select name IndexDate, Value set as output of Compose 3.
Add action Append to array variable, Name as DateArray, Value as variable IndexDate.
Under the Do until loop, add Compose 4, select variable DateArray as its Input.
Initialize variable 3, set Name as Weekends, Type as Integer, Value as 0.
Add an Apply to each, select output from variable DateArray.
Within Apply to each, add a Condition to check if it is Saturday or Sunday.

Or
(
dayOfWeek(items('Apply_to_each')) is equal to 6
dayOfWeek(items('Apply_to_each')) is equal to 0
)

Under If yes branch, Increment variable, Name set as weekends, value as 1.
Under the Apply to each, add Compose5, with variable Weekends as its input.
Add Compose6 with the following code to get the total days between the two dates:

length(variables('DateArray'))

Add Compose 7 to get the workdays:

sub(outputs('Compose_6'),variables('Weekends'))

Hope this could be a workaround for you.

1.PNG2.PNG3.PNG4.PNG5.PNG6.PNG 

 

Best regards,
Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Great, I will have a look through it and mark complete... many thanks. 

Hi @JasonHough ,

 

Does it work for you?

Please mark it as answer if it works for you.

 

Best regards,

Mabel

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

works brilliantly, but i need it to be as dd/MM/YYYY as i based in the UK and the dates will come from SharePoint.. any ideas ? 

works brilliantly, but i need it to be as dd/MM/YYYY as i based in the UK and the dates will come from SharePoint.. any ideas ? 

This is great work but it doesnt work ... So i had a few days (maybe 2 weeks or so) it works fine but if it is a few months it does not work out accuratley. I have been banging my head on this for a long time and it doesnt seem to work. 

 

this is really nice, additionally, may I ask how can i recreate the array of the dates after removing the weekends?

I think I got it!

I declared another array:

st_Titus_0-1603791181338.png

I created an append inside the No branch of my condition. Input is the array SeriesWOWeekend and the Value is Current item

st_Titus_1-1603791345360.png

After the Apply to each action, I added Composed as shown below with seriesWithoutWeekends array as my Input:

st_Titus_2-1603791405833.png

 

The result is like this:

with Oct 31 and Nov 1 falling on weekends

st_Titus_3-1603791508642.png

Now, I believe can create an Apply to each for these dates to Create an event, this is good for automating the creation of series of vacations in calendar.

 

hope this helps! ✌😎

Helpful resources

Announcements
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Microsoft Ignite

Microsoft Power Platform: 2021 Release Wave 1 Plan

Power Platform release plan for the 2021 release wave 1 describes all new features releasing from April through September 2021.

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (19,018)