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.
Solved! Go to Solution.
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.
Best regards,
Mabel
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.
Best regards,
Mabel
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
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:
I created an append inside the No branch of my condition. Input is the array SeriesWOWeekend and the Value is Current item
After the Apply to each action, I added Composed as shown below with seriesWithoutWeekends array as my Input:
The result is like this:
with Oct 31 and Nov 1 falling on weekends
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! ✌😎
Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!
User | Count |
---|---|
36 | |
15 | |
15 | |
13 | |
8 |
User | Count |
---|---|
43 | |
33 | |
25 | |
13 | |
12 |