web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Automatic calculation ...
Power Apps
Unanswered

Automatic calculation of calendar days - Is it possible?

(1) ShareShare
ReportReport
Posted on by 775

Hello everyone,

 

I have built an app that makes it possible to fill out vacation requests. So now I have in the tab "Period" the vacation start and the vacation end. There I can select the days with the calendar option. Next to it I have a field that defines the number of vacation days.

 

PowerSm_0-1630582505987.png

 

 

Now I want the app to automatically count the days from one date to the next and enter them in the field. Is this possible?

For example:

 

Vacation start: 02/09/21
Vacation end: 05/09/21
Number of days: Vacation end - Vacation start (automatically)

 

Best of all, of course, the weekends, that is, Saturday and Sunday are omitted, because you take no vacation.

Is this somehow possible or is this asking too much?

 

Thanks in advance to all!

Categories:
I have the same question (0)
  • Verified answer
    Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    Hey. Use datediff

     

    https://docs.microsoft.com/pt-pt/powerapps/maker/canvas-apps/functions/function-dateadd-datediff 

     

    DateDiff(DatePicker.SelectedDate; DatePicker2.SelectedDate; Days)

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,
    Gonçalo Nogueira

    Check my LinkedIn!

  • Verified answer
    Ram Prakash Duraisamy Profile Picture
    5,593 Super User 2025 Season 2 on at

    Hi @PowerSäm,

     

    You can try DateDiff() Operation.

     

    DateDiff(DateField1.SelectedDate, DateField2.SelectedDate,Days)

     

    to Avoid Negative if startdate is greater than end Date you can try below one

     


    If(DateDiff(DateField1.SelectedDate, DateField2.SelectedDate,Days)<0,
    DateDiff(DateField1.SelectedDate, DateField2.SelectedDate,Days)*-1,
    DateDiff(DateField1.SelectedDate, DateField2.SelectedDate,Days))


    Please mark as Answer if it is helpful and provide Kudos

    https://microsoftcrmtechie.blogspot.com
    https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA

  • Verified answer
    timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @PowerSäm 

    This will give the answer, excluding Saturdays and Sundays. You would replace the hardcoded dates with references to your date pickers.

     

    With({ startDate:DateValue("2021-09-02"),
     endDate:DateValue("2021-09-05")
     },
     RoundDown(DateDiff(startDate, endDate, Days) / 7, 0) * 5 +
     Mod(5 + Weekday(endDate) - Weekday(startDate), 5)
    )

     

    Here, the answer is 1 day (the difference between 02/09 and 03/09 because 04/09 and 05/09 are weekends).

    timl_0-1630588814004.png

     

    You might also want to vote for my idea here, which is to provide an easier way to calculated working days.

     

  • PowerSäm Profile Picture
    775 on at

    @rampprakash @Nogueira1306 Thanks for your quick reply.

     

    This works so far. But now I want that if you enter a date as start date, you can not enter a date as end date, which takes place before the start date. that means, you can only enter as end date a date that comes after the start date.

     

    I hope it was explained clearly enough.

    Thanks in advance!

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    After you select the date, check if

    DatePicker1.SelectedDate < DatePicker2.SelectedDate 

    If yes, Notify the user and reset the datepicker maybe. If not, go ahead

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,
    Gonçalo Nogueira

    Check my LinkedIn!

  • PowerSäm Profile Picture
    775 on at

    @Nogueira1306 Thanks for your replay!

     

    Where do I put it? In Onselect or DefaultDate?

     

    Thanks in advance!

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    None of that. OnChange

     

    Or, if that is a form, before submiting

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,
    Gonçalo Nogueira

    Check my LinkedIn!

  • PowerSäm Profile Picture
    775 on at

    @Nogueira1306 @rampprakash Thanks for your reply.

     

    That works so far, now however still another small attitude thing. If I select the 06/09 as the start date and the 07/09 as the end date, it shows me only one day in the number of days, but in reality there are two, do I have to insert a +1 somewhere?

     

    PowerSm_0-1630913696371.png

     

     

    Thanks in advance!

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    Yes. On that label, set it to be the dateidd + 1

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,
    Gonçalo Nogueira

    Check my LinkedIn!

    Check my User Group (pt-PT)!

  • PowerSäm Profile Picture
    775 on at

    @Nogueira1306 Thanks for your reply!

     

    It is a text input box. Only unfortunately I did not understand where I have to enter it?

    The +1 somewhere under Default somewhere.

     

    Thnak you in advance!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard