1532
Views
20
Comments
Solved
DiffDays without weekend days and national holidays
Question

Hello everyone!


I have an implementation that I've done with DiffDays(). Meanwhile my internal cliente just want that difference without weekend days and holidays.

How can I solve that problem in a simple way?


Thanks for your help!


Best regards,


Ricardo Pereira  

2019-11-25 11-21-58
Ana Reis
 
MVP
Solution

Hi Ricardo,

Like Remco suggested you will need to create an action for that. But you can use DayOfWeek() built in function to know if a specific day is a weekend day. With that you don't need to create an extension, you may do it with OutSystems logic, similar to the algorithm presented by Remco.

Regarding holidays you will need to have them on your system or integrate with some external party that provides that for you. 

Hope this helps.

Ana Reis

2023-12-07 07-51-40
Remco Dekkinga
 
MVP

Hi Ricardo,

You can easily make a diff on the workdays by building an extension with a function like this:

private static int GetNumberOfWorkingDays(DateTime start, DateTime stop)
{
    int days = 0;
    while(start <= stop)
    {
        if(start.DayOfWeek != DayOfWeek.Saturday && start.DayOfWeek != DayOfWeek.Sunday)
        {
            ++days;
        }
        start = start.AddDays(1);
    }
    return days;
}

The holidays is another issue, because they can be different per year and per country/region/company you are in.

Therefore you need to make a table with all the holidays, which has to be maintained for the lifetime of the application and after running the above function you can do a query on the holiday entity and get all holidays that are not in the weekend and deduct them from the result of hte GetNumberOfWorkingDays() function.

I would advise to discuss with your client not include the holidays, because that will be very time-consuming to maintain and it will give wrong results in the future when not properly maintained.

Kind regards,

Remco Dekkinga

2019-11-25 11-21-58
Ana Reis
 
MVP
Solution

Hi Ricardo,

Like Remco suggested you will need to create an action for that. But you can use DayOfWeek() built in function to know if a specific day is a weekend day. With that you don't need to create an extension, you may do it with OutSystems logic, similar to the algorithm presented by Remco.

Regarding holidays you will need to have them on your system or integrate with some external party that provides that for you. 

Hope this helps.

Ana Reis

2021-03-05 13-56-11
Ricardo Pereira
 
MVP

Thank You!


Can You explain to me where I can build this extension?


Best regards,


Ricardo

2019-11-25 11-21-58
Ana Reis
 
MVP

Hi Ricardo,

To create an extension you need to use integration studio. But you can do the logic in Outsystems using only service studio. 

You just need to create a server action and implement the logic like described on the algorithm.

Ana Reis

2021-03-05 13-56-11
Ricardo Pereira
 
MVP

Thank you for your help!


I'll try that!

When I have a result I post here!


Best regards to everyone,

Ricardo Pereira

UserImage.jpg
Edwardo

Ricardo Pereira wrote:

Thank you for your help!


I'll try that!

When I have a result I post here!


Best regards to everyone,

Ricardo Pereira


Hello, Is your problem with holiday over ??? if you already can you share your oml here? because I really need samples to make the same thing about holidays.


Thank you..

UserImage.jpg
Anqi he

Hey just came across this post, has anyone figured out how to create a server action to calculate the workdays between two dates? Thank you.

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

Hi Anqi,

I'm not sure I understand your question. What's there to "figure out"? The solution to the original question has already been answered. It's given various times above.

2018-11-06 14-26-44
Suraj Borade

Hi Anqi

PFA module which contains logic to calculate working days between 2 dates.

Thanks and Regards,

Suraj Borade

Test.oml
2019-08-13 14-31-53
Ana Dias

Suraj Borade wrote:

Hi Anqi

PFA module which contains logic to calculate working days between 2 dates.

Thanks and Regards,

Suraj Borade

Hi Suraj,

I made some changes for my use case, but your oml helped me a lot.


Thank you!



2018-11-06 14-26-44
Suraj Borade

Ana Dias wrote:

Suraj Borade wrote:

Hi Anqi

PFA module which contains logic to calculate working days between 2 dates.

Thanks and Regards,

Suraj Borade

Hi Suraj,

I made some changes for my use case, but your oml helped me a lot.


Thank you!




Your Welcome Ana..!! :)

UserImage.jpg
Fernando André Carvalhal Nogueira

Very usefel, many thanks

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

Hi Edwardo,

Did you see Suraj's post? It contains an example Module.

UserImage.jpg
Edwardo

Kilian Hekhuis wrote:

Hi Edwardo,

Did you see Suraj's post? It contains an example Module.


yes I have seen and implemented it but for the National Holiday I am still confused in applying from the table that I made. Do you have a sample that I can apply ?? 

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

It depends very much on how your list of Holidays is stored. Basically, you want to test for each date whether that's a holiday. So you could do a query each iteration to see if you hit a holiday, but that's not smart performance-wise. Faster would be to query once a list of all holidays, and in your iteration use a ListAny to check whether the date is a holiday.

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

The query goes outside the loop. You only want to query once. Then inside the loop you need the ListAny to check for the holiday.

But this is all really basic programming, you should be able to figure this out yourself!

UserImage.jpg
Edwardo

Kilian Hekhuis wrote:

The query goes outside the loop. You only want to query once. Then inside the loop you need the ListAny to check for the holiday.

But this is all really basic programming, you should be able to figure this out yourself!Okee

Thank youuu sir :))

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

Hi Edwardo,

As discussed in PM, here's an example.

DiffdaysHolidays.oml
UserImage.jpg
Edwardo

Kilian Hekhuis wrote:

Hi Edwardo,

As discussed in PM, here's an example.

Hwaa.. Thank's Sir.


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

You're most welcome. And more importantly, please try to understand the code, rather than copy/paste it ;).

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