cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Community Support
Community Support

Re: Create an array of dates

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

6 REPLIES 6
Highlighted
Community Support
Community Support

Re: Create an array of dates

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

Highlighted
Helper I
Helper I

Re: Create an array of dates

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

Highlighted
Community Support
Community Support

Re: Create an array of dates

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.
Highlighted
Helper I
Helper I

Re: Create an array of dates

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 ? 

Highlighted
Helper I
Helper I

Re: Create an array of dates

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 ? 

Highlighted
Helper I
Helper I

Re: Create an array of dates

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. 

 

Helpful resources

Announcements
FirstImage

Microsoft Ignite 2020

Check out the announcement of Power Platform content at Microsoft Ignite!

thirdImage

Experience what's new for Power Automate

Join us for an in-depth look at the new Power Automate features and capabilities at the free Microsoft Business Applications Launch Event.

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (3,397)