cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
djw1005
Helper I
Helper I

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

 

 

 

 

 

 

 

 

Anonymous
Not applicable

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

Take a short Community User Survey | Help us make your experience better!

To ensure that we are providing the best possible experience for Community members, we want to hear from you!    We value your feedback! As part of our commitment to enhancing your experience, we invite you to participate in a brief 15-question survey. Your insights will help us improve our services and better serve the community.    👉Community User Survey    Thank you for being an essential part of our community!    Power Platform Engagement Team  

Tuesday Tip | How to Get Community Support

It's time for another Tuesday Tip, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.       This Week: All About Community Support Whether you're a seasoned community veteran or just getting started, you may need a bit of help from time to time! If you need to share feedback with the Community Engagement team about the community or are looking for ways we can assist you with user groups, events, or something else, Community Support is the place to start.   Community Support is part of every one of our communities, accessible to all our community members.   Within each community's Community Support page, you'll find three distinct areas, each with a different focus to help you when you need support from us most. Power Apps: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pa_community_support Power Automate: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpa_community_support Power Pages: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpp_community_support Copilot Studio: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pva_community-support   Community Support Form If you need more assistance, you can reach out to the Community Team via the Community support form. Choose the type of support you require and fill in the form accordingly. We will respond to you promptly.    Thank you for being an active part of our community. Your contributions make a difference!   Best Regards, The Community Management Team

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!    

Calling all User Group Leaders and Super Users! Mark Your Calendars for the next Community Ambassador Call on May 9th!

This month's Community Ambassador call is on May 9th at 9a & 3p PDT. Please keep an eye out in your private messages and Teams channels for your invitation. There are lots of exciting updates coming to the Community, and we have some exclusive opportunities to share with you! As always, we'll also review regular updates for User Groups, Super Users, and share general information about what's going on in the Community.     Be sure to register & we hope to see all of you there!

April 2024 Community Newsletter

We're pleased to share the April Community Newsletter, where we highlight the latest news, product releases, upcoming events, and the amazing work of our outstanding Community members.   If you're new to the Community, please make sure to follow the latest News & Announcements and check out the Community on LinkedIn as well! It's the best way to stay up-to-date with all the news from across Microsoft Power Platform and beyond.    COMMUNITY HIGHLIGHTS   Check out the most active community members of the last month! These hardworking members are posting regularly, answering questions, kudos, and providing top solutions in their communities. We are so thankful for each of you--keep up the great work! If you hope to see your name here next month, follow these awesome community members to see what they do!   Power AppsPower AutomateCopilot StudioPower PagesWarrenBelzDeenujialexander2523ragavanrajanLaurensMManishSolankiMattJimisonLucas001AmikcapuanodanilostephenrobertOliverRodriguestimlAndrewJManikandanSFubarmmbr1606VishnuReddy1997theMacResolutionsVishalJhaveriVictorIvanidzejsrandhawahagrua33ikExpiscornovusFGuerrero1PowerAddictgulshankhuranaANBExpiscornovusprathyooSpongYeNived_Nambiardeeksha15795apangelesGochixgrantjenkinsvasu24Mfon   LATEST NEWS   Business Applications Launch Event - On Demand In case you missed the Business Applications Launch Event, you can now catch up on all the announcements and watch the entire event on-demand inside Charles Lamanna's latest cloud blog.   This is your one stop shop for all the latest Copilot features across Power Platform and #Dynamics365, including first-hand looks at how companies such as Lenovo, Sonepar, Ford Motor Company, Omnicom and more are using these new capabilities in transformative ways. Click the image below to watch today!   Power Platform Community Conference 2024 is here! It's time to look forward to the next installment of the Power Platform Community Conference, which takes place this year on 18-20th September 2024 at the MGM Grand in Las Vegas!   Come and be inspired by Microsoft senior thought leaders and the engineers behind the #PowerPlatform, with Charles Lamanna, Sangya Singh, Ryan Cunningham, Kim Manis, Nirav Shah, Omar Aftab and Leon Welicki already confirmed to speak. You'll also be able to learn from industry experts and Microsoft MVPs who are dedicated to bridging the gap between humanity and technology. These include the likes of Lisa Crosbie, Victor Dantas, Kristine Kolodziejski, David Yack, Daniel Christian, Miguel Félix, and Mats Necker, with many more to be announced over the coming weeks.   Click here to watch our brand-new sizzle reel for #PPCC24 or click the image below to find out more about registration. See you in Vegas!       Power Up Program Announces New Video-Based Learning Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram. These include a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the image below to find out more!   UPCOMING EVENTS Microsoft Build - Seattle and Online - 21-23rd May 2024 Taking place on 21-23rd May 2024 both online and in Seattle, this is the perfect event to learn more about low code development, creating copilots, cloud platforms, and so much more to help you unleash the power of AI.   There's a serious wealth of talent speaking across the three days, including the likes of Satya Nadella, Amanda K. Silver, Scott Guthrie, Sarah Bird, Charles Lamanna, Miti J., Kevin Scott, Asha Sharma, Rajesh Jha, Arun Ulag, Clay Wesener, and many more.   And don't worry if you can't make it to Seattle, the event will be online and totally free to join. Click the image below to register for #MSBuild today!   European Collab Summit - Germany - 14-16th May 2024 The clock is counting down to the amazing European Collaboration Summit, which takes place in Germany May 14-16, 2024. #CollabSummit2024 is designed to provide cutting-edge insights and best practices into Power Platform, Microsoft 365, Teams, Viva, and so much more. There's a whole host of experts speakers across the three-day event, including the likes of Vesa Juvonen, Laurie Pottmeyer, Dan Holme, Mark Kashman, Dona Sarkar, Gavin Barron, Emily Mancini, Martina Grom, Ahmad Najjar, Liz Sundet, Nikki Chapple, Sara Fennah, Seb Matthews, Tobias Martin, Zoe Wilson, Fabian Williams, and many more.   Click the image below to find out more about #ECS2024 and register today!     Microsoft 365 & Power Platform Conference - Seattle - 3-7th June If you're looking to turbo boost your Power Platform skills this year, why not take a look at everything TechCon365 has to offer at the Seattle Convention Center on June 3-7, 2024.   This amazing 3-day conference (with 2 optional days of workshops) offers over 130 sessions across multiple tracks, alongside 25 workshops presented by Power Platform, Microsoft 365, Microsoft Teams, Viva, Azure, Copilot and AI experts. There's a great array of speakers, including the likes of Nirav Shah, Naomi Moneypenny, Jason Himmelstein, Heather Cook, Karuana Gatimu, Mark Kashman, Michelle Gilbert, Taiki Y., Kristi K., Nate Chamberlain, Julie Koesmarno, Daniel Glenn, Sarah Haase, Marc Windle, Amit Vasu, Joanne C Klein, Agnes Molnar, and many more.   Click the image below for more #Techcon365 intel and register today!     For more events, click the image below to visit the Microsoft Community Days website.      

Tuesday Tip | Update Your Community Profile Today!

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   We're excited to announce that updating your community profile has never been easier! Keeping your profile up to date is essential for staying connected and engaged with the community.   Check out the following Support Articles with these topics: Accessing Your Community ProfileRetrieving Your Profile URLUpdating Your Community Profile Time ZoneChanging Your Community Profile Picture (Avatar)Setting Your Date Display Preferences Click on your community link for more information: Power Apps, Power Automate, Power Pages, Copilot Studio   Thank you for being an active part of our community. Your contributions make a difference! Best Regards, The Community Management Team

Users online (3,198)