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

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

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including 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 link below to sign up today! https://aka.ms/PowerUp  

Super User of the Month | Ahmed Salih

We're thrilled to announce that Ahmed Salih is our Super User of the Month for April 2024. Ahmed has been one of our most active Super Users this year--in fact, he kicked off the year in our Community with this great video reminder of why being a Super User has been so important to him!   Ahmed is the Senior Power Platform Architect at Saint Jude's Children's Research Hospital in Memphis. He's been a Super User for two seasons and is also a Microsoft MVP! He's celebrating his 3rd year being active in the Community--and he's received more than 500 kudos while authoring nearly 300 solutions. Ahmed's contributions to the Super User in Training program has been invaluable, with his most recent session with SUIT highlighting an incredible amount of best practices and tips that have helped him achieve his success.   Ahmed's infectious enthusiasm and boundless energy are a key reason why so many Community members appreciate how he brings his personality--and expertise--to every interaction. With all the solutions he provides, his willingness to help the Community learn more about Power Platform, and his sheer joy in life, we are pleased to celebrate Ahmed and all his contributions! You can find him in the Community and on LinkedIn. Congratulations, Ahmed--thank you for being a SUPER user!

Tuesday Tip: Getting Started with Private Messages & Macros

Welcome to 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.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   This Week's Tip: Private Messaging & Macros in Power Apps Community   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!   Our Knowledge Base article about private messaging and macros is the best place to find out more. Check it out today and discover some key tips and tricks when it comes to messages and macros:   Private Messaging: Learn how to enable private messages in your community profile and ensure you’re connected with other community membersMacros Explained: Discover the convenience of macros—prewritten text snippets that save time when posting in forums or sending private messagesCreating Macros: Follow simple steps to create your own macros for efficient communication within the Power Apps CommunityUsage Guide: Understand how to apply macros in posts and private messages, enhancing your interaction with the Community For detailed instructions and more information, visit the full page in your community today:Power Apps: Enabling Private Messaging & How to Use Macros (Power Apps)Power Automate: Enabling Private Messaging & How to Use Macros (Power Automate)  Copilot Studio: Enabling Private Messaging &How to Use Macros (Copilot Studio) Power Pages: Enabling Private Messaging & How to Use Macros (Power Pages)

Tuesday Tip: Subscriptions & Notifications

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week: All About Subscriptions & Notifications We don't want you to a miss a thing in the Community! The best way to make sure you know what's going on in the News & Announcements, to blogs you follow, or forums and galleries you're interested in is to subscribe! These subscriptions ensure you receive automated messages about the most recent posts and replies. Even better, there are multiple ways you can subscribe to content and boards in the community! (Please note: if you have created an AAD (Azure Active Directory) account you won't be able to receive e-mail notifications.)   Subscribing to a Category  When you're looking at the entire category, select from the Options drop down and choose Subscribe.     You can then choose to Subscribe to all of the boards or select only the boards you want to receive notifications. When you're satisfied with your choices, click Save.     Subscribing to a Topic You can also subscribe to a single topic by clicking Subscribe from the Options drop down menu, while you are viewing the topic or in the General board overview, respectively.     Subscribing to a Label Find the labels at the bottom left of a post.From a particular post with a label, click on the label to filter by that label. This opens a window containing a list of posts with the label you have selected. Click Subscribe.     Note: You can only subscribe to a label at the board level. If you subscribe to a label named 'Copilot' at board #1, it will not automatically subscribe you to an identically named label at board #2. You will have to subscribe twice, once at each board.   Bookmarks Just like you can subscribe to topics and categories, you can also bookmark topics and boards from the same menus! Simply go to the Topic Options drop down menu to bookmark a topic or the Options drop down to bookmark a board. The difference between subscribing and bookmarking is that subscriptions provide you with notifications, whereas bookmarks provide you a static way of easily accessing your favorite boards from the My subscriptions area.   Managing & Viewing Your Subscriptions & Bookmarks To manage your subscriptions, click on your avatar and select My subscriptions from the drop-down menu.     From the Subscriptions & Notifications tab, you can manage your subscriptions, including your e-mail subscription options, your bookmarks, your notification settings, and your email notification format.     You can see a list of all your subscriptions and bookmarks and choose which ones to delete, either individually or in bulk, by checking multiple boxes.     A Note on Following Friends on Mobile Adding someone as a friend or selecting Follow in the mobile view does not allow you to subscribe to their activity feed. You will merely be able to see your friends’ biography, other personal information, or online status, and send messages more quickly by choosing who to send the message to from a list, as opposed to having to search by username.

Users online (4,290)