How do I round a number down to the closest integer in OutSystems without using JavaScript Math.Floor() ?

My case: I have an amount of days (using DiffDays) and need to substract the weekends. So if the difference between dates is 33 days, there are 4 weekends in between and the amount of working days is 33 - 8 = 25. The round method can not be set to round down at all times. The dates are added by the user and the working days in between should show up immediately.

Any way to still just to the calculations in the expression used to display the working days?

Working day calculations should also account for public holidays, it's not enough to just get rid of weekends. Also, your calculation is flawed: if you take a span of Monday through the Friday of next week, that's 12 days, with only one weekend in between. But if you take a span of 12 days from Saturday to the Wednesday of the second week, there's two weekends in between (but your calculation would yield only one). And if you start on Sunday, there's only 1.5 weekend (three days).

That said, if you assign a Decimal value to an Integer variable, you automatically get a truncated/floored result, you do not need a special function for that.

I don't need to get the DayOfWeek from my date. What I mean is that I want to know how many WORKING days are inbetween 2 dates. So this means getting rid of all weekends. For as far as I know OutSystems does not have a standard functionality to do this, right?

So what I thought is that if you calculated the amount of days and divide by seven you will have the amount of weeks past. The amount of weekends that have occured is always the Floor() number. For instance, 33 days between two dates means that 4,7 weeks have past. That would be equal to 4 weekends. So the Floor() logic needs to rounds 4,7 to 4. By that I can multiple by 2 and substract it from the days coming from DiffDay to know the working days.

Working day calculations should also account for public holidays, it's not enough to just get rid of weekends. Also, your calculation is flawed: if you take a span of Monday through the Friday of next week, that's 12 days, with only one weekend in between. But if you take a span of 12 days from Saturday to the Wednesday of the second week, there's two weekends in between (but your calculation would yield only one). And if you start on Sunday, there's only 1.5 weekend (three days).

That said, if you assign a Decimal value to an Integer variable, you automatically get a truncated/floored result, you do not need a special function for that.

Thanks for your reply! I am aware of the fact that holidays are not taken into account. This is not needed since we work with a lot of off shore people who have different holidays. I have already set the date input field so that users are not able to select a weekend day (which they probably even would never do since they all know that working days should be chosen as start days and end dates).

I already fixed this issue by using a SQL statement with a FLOOR in it, but will defitenly give your solution a try! Should be quicker that way ;)

It is unclear how you are using Math functions with Weekends logic but, for your question related to rounding a number to near integer, you can always use Math client & server functions without using javascripts.

Hi Max, Yes ceiling and floor are not currently built in functions as per in this idea: https://www.outsystems.com/ideas/678/built-in-funtions I can see that previously it was also pointed out but still not available. Let's hope it will be added soon.

Meanwhile I saw one component - MathUtils. Take a look. Its having MathFloor. You can also create a small code with C# and wrap in your environment extension.

Hi All,

How do I round a number down to the closest integer in OutSystems without using JavaScript Math.Floor() ?

My case: I have an amount of days (using DiffDays) and need to substract the weekends. So if the difference between dates is 33 days, there are 4 weekends in between and the amount of working days is 33 - 8 = 25. The round method can not be set to round down at all times. The dates are added by the user and the working days in between should show up immediately.

Any way to still just to the calculations in the expression used to display the working days?

Regards,

Max