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 / Start and end date and...
Power Apps
Answered

Start and end date and then jump

(0) ShareShare
ReportReport
Posted on by 193

I have a start and end date.

Say start date is January 1 and end date is January 31.
How do I manage to get a list that shows .

January 1st
January 2nd
January 14
January 15
January 28
January 29

etc.

 

So the date should be 2 days each time and then jump 14 days. The end date can go on until, for example, the end of May.

This must appear in an edit screen (so it must first be visible) and then it must be written into a sql table after pressing an ok button.

 

 

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

    @rvdhorst 

    Your example of days does not match your request...

    There are 13 days between Jan 1 and Jan 14.  Yet, there are 14 days between Jan 14 and Jan 28!

    So the "jump" of days is not the same.

     

    An example formula that would provide a consistent jump of 14 days with a start and end range would be the following:

    With({_start: Date(2021,1,1), _end:Date(2021,5,31), _jumpDays:14},
     Ungroup(
     ForAll(Sequence(DateDiff(_start, _end, Days), 1, _jumpDays),
     Table({Date: DateAdd(_start, Value-1, Days)}, {Date: DateAdd(_start, Value, Days)})
     ),
     "Value"
     )
    )

    This will produce a table with a single column called Date.  The Dates would be as you wanted based on your description - but not your example dates because of the discrepancy.

    RandyHayes_0-1639756995511.png

     

    I hope this is helpful for you.

     

  • rvdhorst Profile Picture
    193 on at

    Hi Randy,

    Thank you very much for your quick reply.

     

    Where should I put this code? If I place this under an onselect under a button, it does not work unfortunately.

    How do I get this working in a SQL database? What is the variable I need to write?


    Raymond

     

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

    @rvdhorst 

    The Formula provided can be used as an Items property of any control that has an Items property...like a Gallery.  It's not based on any OnSelect or variables, it is a PowerApp formula for a table.

     

    As far as what you want to do with that next (i.e. in relation to SQL) is not known as you didn't mention what you really wanted to submit.  You mentioned an Edit screen - is that to say there is some EditForm?  And then writing to a SQL table...but what?  Provide some more detail on your SQL table and I can expand a little further.

  • rvdhorst Profile Picture
    193 on at

    Thanks Randy,

    This indeed works.

     

    What I would like if someone enters a start and end date via a Datepicker, then the gallery will be shown. If the result/value is approved, the date will be written into a SQL Table by an ok button in a table test table, the record is called Date) So in the table test table there is a record Date.

     

    Raymond

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

    @rvdhorst 

    So then on your approve/okay button, the OnSelect would use the Gallery as the datasource to create new records.

    The formula would be:

    Collect(yourSQLtableDataSource,
     ForAll(yourGallery.AllItems,
     {Date: Date}
     )
    )

    Again, assuming that the column name in your SQL table is Date, then this will create x number of records in your table corresponding to the gallery items.

  • rvdhorst Profile Picture
    193 on at

    Thanks Randy,

    How can I start working with a Datepicker and not with fixed days?

     

    Raymond

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

    @rvdhorst 

    Just replace that in the formula to the yourDatePicker.SelectedDate.

    Ex.

    With({_start: DatePickerStart.SelectedDate, _end: DatePickerEnd.SelectedDate, _jumpDays:14},
     Ungroup(
     ForAll(Sequence(DateDiff(_start, _end, Days), 1, _jumpDays),
     Table({Date: DateAdd(_start, Value-1, Days)}, {Date: DateAdd(_start, Value, Days)})
     ),
     "Value"
     )
    )

     

  • rvdhorst Profile Picture
    193 on at

    Thank you very much Randy

    I'll get started on this tomorrow. Can I still ask if I have any questions? I'll mark it as resolved. A very nice day.

    Raymond

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

    @rvdhorst 

    Sounds good.  Yes, feel free to ask if you run into issues.

  • rvdhorst Profile Picture
    193 on at

    Hello Randy,

     

    What am I doing wrong? If I specify an end date, it doesn't stop there.

    See picture

     

     

    Untitled.png

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 350 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 318

#3
Mohsin Ali Profile Picture

Mohsin Ali 220

Last 30 days Overall leaderboard