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

Dates between two dates

Is there a way of creating an array of dates between a start and end  date?

 

For example 

01/12/2018 Start

05/12/2018 Finish

 

This would record 01/12/2018...02/12/2018 etc 

 

 

18 REPLIES 18
efialttes
Community Champion
Community Champion

Hi

You can try with Variables, Do Until, adddays() array() and union(). Both adddays() array() and union() are functions defined here https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language

 

Let's assume you have stored the StartDate inside a variable called the same. Also for EndDate. I guess both dates shall be defined in datetime string which match ISO 8601 format ('o'), in order to apply adddays() function later on.

 

 

So, you initialize two array variables (myArray and auxArray) with the following expression:

array(variables('StartDate'))

 

You also initialize two string variables (indexDate and auxDate) with the following dynamic content:

variables('StartDate')

 

then you add the Do Until loop:

 

set indexDate to the following expression:

adddays(auxDate,1)

 

set auxDate to the following dynamic content:

variables('indexDate')

 

set myArray to the following expression

union(auxArray,array(variables('indexDate')))

 

set auxArray to the following dynamic content:

variables('myArray')

 

The Do Until shall be stopped once you reach the following condition:

equals(variables('EndDate'),variables('indexDate'))

 

In case it's needed, there is an intesting thread explaining how to match ISO 8601 format ('o') here:

https://powerusers.microsoft.com/t5/Building-Flows/formatDateTime-to-ISO-8061-format-for-Create-Even...

 

I haven't tested it myself, let's hope I haven't missed and single quote, parenthesis etc.

Hope this helps

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

v-xida-msft
Community Support
Community Support

Hi @djw1005,

 

I agree with @efialttes’s thought almost, I think you have two variables to store StartDate and EndDate on your side, in addition, both dates should be defined in datetime string which match ISO 8601 format (‘o’).

I have made a test on my side and please take a try with the following workaround:

  • Choose a proper trigger, here I use Flow Button trigger.
  • Add a Compose action, which represents StartDate. Input parameter set to following formula:
addDays(utcNow(),42,'MM/dd/yyyy')
  • Add a Compose 2 action (Called EndDate on my side), which represents EndDate. Input parameter set to following formula:
addDays(utcNow(),162,'MM/dd/yyyy')
  • Add a Variables-> “Initialize variable” action, Name set to IndexDate, type set to String, Value set to Ouput content of “Compose” action.
  • Add a Variables-> “Initialize variable” action, Name set to DateArray, Type set to Array, Value set to following formula:
array(outputs('Compose'))
  • Add a “Do Until” action, left input box set to variable IndexDate, right input box set to Output content of “EndDate” action, in middle drop down, choose is equal to.
  • Within “Do Until”, Add a “Compose 3” action, Input set to following formula:
addDays(variables('IndexDate'),1,'MM/dd/yyyy')

 

Add “Set variable” action, Name choose IndexDate, Value set to output of “Compose 3” action.

 

Add “Append to array variable” action, Name set to DateArray, Value set to variable IndexDate.

  • Add a “Compose 2” action, Input parameter set to variable DateArray.

Image reference:10.JPG

 

11.JPG

The flow works successfully as below:14.JPG

 

 

12.JPG

 

13.JPG

 

Best regards,

Kris

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

I have followed the instructions but I get the following error when it's run

 

error.PNG

 

 

Hi @v-xida-msft

"Append to Array Variable" action block is much much more intuitive than using union() function as I suggested

Thanks for sharing!

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

Thanks I have now got that working.... it's now righting to a sharepoint list as well

 

My question is now, how could I use this information to search within flow for existing holidays. 

 

I have created a for each loop, but when I search for say the index date with the dates booked off field it doesn't find anything oddly

items1.PNG

Hi

I guess the screenshot you are sharing is from your Sharepoint List, right? And also you want to iterate through the array items, right?

If so, take into account your sharepoint column is probable string based, so you need to convert it into an array first. Once you have a real array, you can add an Apply to Each

Hpe this helps

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

What that range is the array that is generated from the between dates on the request.

 

What I want to do is take the existing holidays and see if the dates  have been booked. 

 

So for example if someone books 12/01/2017 to 12/05/2017 but then tries to book 12/03/2017 it should reject this.

 

Just not sure how to achieve it.

OK, so you have implemented an Apply to Each using variables('DateArray') as the input, right?

If so, this Apply to Each will iterate over all the date items inside the array

Then I guess you want to compare each date item with a target date in order to avoid duplicates, right?

 

IMO, there is also another aproach with less computing effort if the vacation periods are long, that is, since the array contains all dates between Start Date and End Date, you can compare your target date with first array item and last array item. If so, please take into account you will probably need to convert it into a date format valid for MS Flow.

 

Hope this helps

 

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

Really new to all this and it's very head scratching.....

 

So I have an array of say 

12/01/2017 

12/02/2017

12/03/2017

..

..

12/10/2017

 

How do I search each date, against the preexisting holidays?

 

Hi again

I guess the preexisting holidays are stored in the Sharepoint List, I mean, the screenshot you shared a few moments ago, right?

If so, how many items per employee do you store in the Sharepoint list? One per vacation period so an employee can have more than one item in the SP list, or one item per employee, so you append different vacation periods in the same array?

Also, your Flow is the only entry point to create items in this SP list?

I mean, almosr everything depends on the approach you followed so far

BR

 

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

Each item in the sharepoint list is an individual request that a person submits

 

There could be many items per employee....

 

I am beginnging to wish I'd not started this....

Hi again

 

So, you need to implement a Get Items action block and filter by employee. You will get then an array of N SP list items, all of them vacation requests from the employee.

You need to add an Apply to Each taking this array of SP items as input.

And you also have a new vacation request stored in an array Flow variable as you followed @v-xida-msft instructions.

 

If your Flow is the only entry point to add items in the SP list, my suggestion is to store dates in a Flow valid format, I mean datetime string which match ISO 8601 format ('o').

 

Also you need to convert the SP column value where you store the array into a real array (I mean, on SP this is stored as a string). One option is to use string manipulation functions to remove both [ and ] from the string, then use split() function.

 

Then you can take Start Date from SP item vacation period, also End Date from SP item vacation period. I guess you can use first() and last() for such purpose.

 

Finally if either "new vacation request Start Date" or "new vacation request End Date" are between "employee SP item vacation period" you are currently evaluating, the new request shall be rejected and the Flow terminated (for example, via TErminate action block). IF not, then Apply to Each will keep on evaluating against the next "employee SP item vacation period"

 

In order to compare dates, there are several threads in this community explaining how to do it. Also this excellent post explains how to do it by using ticks() function

https://flow.microsoft.com/en-us/blog/email-digest-date-manipulations/

 

Hope this helps

 

 

 

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

Anonymous
Not applicable

I know this post is an year old. But found this amazing article that helped.

 

Do it in PowerApps

pit850
Frequent Visitor

Hi,

 

for the first. thanks for the post.

I've been looking for some time a way to calculate the period between dates. 

Unfortunately, the function datediff is not available in flow.
So i have try with your flow. 
everything so good. Unfortunately, I can not put my dates in the array. the following error message occurs.
 
 ActionFailed. An action failed. No dependent actions succeeded.
 

InvalidTemplate. Unable to process template language expressions in action 'Verfassen' inputs at line '1' and column '2595': 'The template language function 'addDays' expects its first parameter to be a string that contains the time. The provided value is of type 'Array'. Please see https://aka.ms/logicexpressions#adddays for usage details.'.

 

What am i doing wrong?

Variable "Startdate"   

addDays(trigstartdate 1.pnggerBody()?['EventDate'],0,'JJJJ-MM-TT')
 
 
 
Variable "Enddate"
Enddate 1.png
addDays(triggerBody()?['EndDate'],0,'JJJJ-MM-TT')
 
 
Indexdate.png
array(triggerBody()?['EventDate'])
 
DateArray.png
array(outputs('Enddate_1'))
 
 
 
 
 

 

 

 

 

Hey guys,

 

I was able to rebuild a working solution with help of the reference link in a previous link and the instruction here. The flow will provide the number of total days between two dates, weekend days and working days (Mon-Fri) in this period. The pictures are step by step from creating a new item on a sp list until the output. 

1.PNG2.PNG3.PNG4.PNG5.PNG

 

 

 

 

 

 

 

 

Thanks for sharing, that really helped me a lot. What I can't find out, though, is how to subtract local holidays from the calculated days. 

 

Feels like I've tried everything but nothing works.

 

Used your guide above and everything works. But now I have to find out if one of the local holidays, on the list below, is equal one of the dates counted and then subtract with one from the number of days.

 

Could you help me do that?

 

 

 

 Holidays.png

Dear tsl,

IMO you have to add a case where if the local holiday exists in the selected date range, reduce the number of holidays by 1.

 

Following are my observations:

  1. I don't see the leave balance being calculated through the flow. Once the user applies for leave(s), the leave balance should be updated.
  2. Add a logic in probably the "dates array", that if a holiday falls between the date ranges (Start date and end date) do not increment the holiday counter. Just skip.

 

Regards,

Dhawal Seth

Ali_Cabral
Frequent Visitor

May be a bit late in this response but hopefully if someone else finds this like I did but couldn't understand there is quite a simple solution using the ticks() expression. If you want to find the ticks of the date there are plenty of online convertors like this one http://www.datetimetoticks-converter.com/ and then using a condition like the below.

 

 
 
 

image.png

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages