cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JasonHough
Level: Powered On

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 Team
Community Support Team

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
Community Support Team
Community Support Team

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

JasonHough
Level: Powered On

Re: Create an array of dates

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

Community Support Team
Community Support Team

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.
JasonHough
Level: Powered On

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 ? 

JasonHough
Level: Powered On

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
JasonHough
Level: Powered On

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 Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Users Online
Currently online: 360 members 4,732 guests
Please welcome our newest community members: