34
Views
16
Comments
Working Days Calculation Excluding Weekends and Half-Days

Hi,

I am trying to calculate working days in my application, where weekends (Saturday and Sunday) should be excluded. Additionally, if the user selects half-days, those should also be deducted from the total.

How can I implement this in my application?

LeaveApplication.oml
2026-01-28 16-57-48
Mihai Melencu
Champion

Hi @ATUL TIWARI ,

Unfortunately, your OML includes a core module that we don’t have access to (LeaveApplication Core). Because of that, we can’t modify it, as it currently has errors on our side. 

Also, could you clarify what period you want to use for calculating the working days? And are these the actual working days or days deducted?

2025-12-30 15-52-56
ATUL TIWARI

I am developing a form where users can select a start date and an end date. Based on this date range, I need to calculate the total number of working days, excluding Saturdays and Sundays, regardless of the month.

After calculating the total working days, I also need to check if the “Half Day” option is selected. If it is true, then 0.5 day should be deducted from the total count.

Finally, the calculated total number of days should be stored in the database when the form is submitted. 

2026-01-28 16-57-48
Mihai Melencu
Champion

Like Siya mentioned, the approach is basically a classic while StartDate <= EndDate, where you calculate the total inside the loop. In OS, you simulate this using an If node.

The flow is:

  1. Start from the selected start date
  2. Iterate day by day until you reach the end date
  3. Skip Saturdays and Sundays
  4. Count only working days
  5. After the loop finishes, subtract 0.5 if the half-day option is selected


I created this logic in a client action called CalculateTotalDays, and I added in your logic flow for RequestOnClick.

LeaveApplication_updated'.oml
2019-01-07 16-04-16
Siya
 
MVP

@ATUL TIWARI : Use an ad hoc loop to iterate from the start date to the end date. For each date, check the result of DayOfWeek(). If it returns 0 (Sunday) or 6 (Saturday), skip that date; otherwise, include it in the total.

2019-01-07 16-04-16
Siya
 
MVP

@ATUL TIWARI : Thanks @Mihai Melencu for the implementation. btw logic  for half-days should be relookedinto. To me it looks like if half-days  should be for all days not just one day i.e if some one applied leave for a whole but marked as half days then the total should be 2.5 instead of 4.5 days. @ATUL TIWARI : Please confirm this.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Although looping works, and will be fast enough for any modern computer, it can be done smarter. Since weekends are predictable, it's possible to calculate the number of weekend days within a certain period once you know the first day of that period. I'll leave it as an exercise to the reader to come up with the exact formula :).

2026-01-08 12-12-29
shreyans wadyalkar

You can calculate working days by looping from start date to end date and counting only weekdays (excluding Saturday and Sunday using WeekDay()). Then subtract 0.5 for each half-day selected (start/end). This approach is simple, reliable, and handles edge cases like weekends and partial days correctly. 

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

This answer has been given already 3 days ago, and you used AI to generate the answer. Please firsat read what anwers have been given before answering yourself, and don't post if the answer was already posted. (And ideally also don't use AI!)

2026-01-08 12-12-29
shreyans wadyalkar

Killan yes i didn't read the all previous answer, I will check from next time but its was not AI generated its something which is implemented in my POC App.


I just used AI to rephrase answer wording.


Its good that you are evaluating closely. But requesting you to don't mark used as AI without confirming.

Thank you !

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Shreyans,

I removed the AI tag, but note that "rephrasing with AI" often leads to answers indistinguishable from an AI answer. Especially the last sentence, "This approach is simple, reliable, and handles edge cases like weekends and partial days correctly" is so typical of a ChatGPT or other LLM response, that it's hard to believe it's just a "rephrase". So you might want to be careful letting an LLM redirect your words.

It's better to speak somewhat incorrect English, than to be taken for AI!

2026-01-08 12-12-29
shreyans wadyalkar

Yup, Thanks and ok sure i will try that to be natural and please ensure before marking AI or anything because it leads to downs votes also that's why 
btw No issue with so, and ok thanks for advice 

Thank you !

 

2024-10-05 13-30-20
Huy Hoang The

Hi,
I'm also working on a small scheduling app, and I'd like to ask if there's a better or faster way than using a loop. 

For example, I'm calculating the number of working days for a long-serving employee.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Computers are nowadays more than fast enough to calculate it using a loop within a fraction of a second, even if it's years and years you want to calculate. You shouldn't optimize before you know it's needed!

2019-01-07 16-04-16
Siya
 
MVP

Agree with @Kilian Hekhuis. However if some one is really need a formulae here it is

weekdays = DecimalToInteger((DiffDays(StartDate, EndDate) + 1) / 7) * 5 + Max(0,Min(5, DayOfWeek(StartDate) + Mod(DiffDays(StartDate, EndDate) + 1, 7)) - Min(5, DayOfWeek(StartDate)))

weekdays = full weeks (×5) + weekdays from remaining days.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Now that's what I call a formula :D.

2014-10-21 20-15-17
Alberto Ferreira

Hi @ATUL TIWARI  


For the difference workdays between two dates you can try the forge 

https://www.outsystems.com/forge/component-overview/16516/dateplus 

Best regards

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.