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 Apps / How to calculate dates...
Power Apps
Answered

How to calculate dates between two dates selected by user?

(0) ShareShare
ReportReport
Posted on by 47

Hi Community,

I don't know if this is doable in PowerApps. I am trying to calculate dates between two dates selected by user. For example.

If the user selects 01/28/2022 and 02/01/2022. I want to display 01/29/2022, 01/30/2022, 01/31/2022 in a text box.

 

Can this be achieved inside PowerApps? Thanks in advance.. Please help!

Categories:
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @bakgou1 

    Assuming you have two datepickers (dp1 and dp2), then your Default property on a Textbox would be:

    With({_txt:
     Concat(Sequence(DateDiff(dp1.SelectedDate, dp2.SelectedDate, Days), 0), 
     Text(DateAdd(dp1.SelectedDate, Value, Days), ShortDate) & ", "
     )
    },
     Left(_txt, Len(_txt)-2)
    )

     

    I hope this is helpful for you.

  • Digital Profile Picture
    1,207 on at

    You use DateDiff and Date Add to make a collection of inbetween dates that you can display in a drop down.

     

    Button.OnSelect

    With(
     {
     locDateDiff: DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate)
     },
     ForAll(
     Sequence(locDateDiff),
     Collect(
     colInbetweenDates,
     {
     date:DateAdd(DatePicker1.SelectedDate,Value)
     }
     )
     )
    )

     

    Screen Shot 2022-02-02 at 11.41.33.png

     

  • bakgou1 Profile Picture
    47 on at

    @RandyHayes I appreciate your quick response. It worked like a gem! 😀

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Digital 

    No collection is needed for this for a text box.  Plus, your ForAll is backward.  You are using it like a ForLoop in some development language.

    If you for some reason wanted this in an in-memory database in the app, then your formula would be written as:

    ClearCollect(colInbetweenDates,
     ForAll(
     Sequence(DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate, Days), 0),
     {
     date: DateAdd(DatePicker1.SelectedDate, Value)
     }
     ) 
    )

    Of course, this would have to then be done in a behavioral property ONLY.  So it would have to be initiated. 

     

    ForAll is a function that returns a table.  It will do this despite how you use it.  So in your case, it is still generating a table with a duplicate of all the collection returned from the Collect function in each row of the sequence.  All of this is then put together as a table with (in your formula) a record with a single column called Value that will have the entire collection duplicated in the column for each row.

    In this example, it is not extreme, but using a ForAll like that will, in larger examples, consume a lot of memory and resources to generate...and then you completely discard it when done in your formula.  So the process is wasted - but still performance is consumed.

     

     

  • Ugur_Dmn Profile Picture
    2 on at

    Hi,

     

    Is there a way exract the "weekends"? It will be very help to me, thanks for your response!

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 Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 139

Last 30 days Overall leaderboard