web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Create an array of dates
Power Automate
Answered

Create an array of dates

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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. 

Categories:
  • Verified answer
    v-yamao-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,


    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 Power Platform Member Profile Picture
    Microsoft Employee on at

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

  • v-yamao-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

     

    Does it work for you?

    Please mark it as answer if it works for you.

     

    Best regards,

    Mabel

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    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 ? 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    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 ? 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    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. 

     

  • st_Titus Profile Picture
    12 on at

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

  • st_Titus Profile Picture
    12 on at

    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! ✌😎

  • lizgov Profile Picture
    2 on at

    How would I apply this if I wanted to read the end date in a column.

    My situation is where I need to create this function as a flow: Total LWOP hours - ((work days between today and LWOP END Date) * (daily hours)) = LWOP hours to today. 

     

    Any help is appreciated!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 423

#2
11manish Profile Picture

11manish 308 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 177

Last 30 days Overall leaderboard