DiffDays without weekend days and national holidays

DiffDays without weekend days and national holidays

  

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  

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

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

Thank You!


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


Best regards,


Ricardo

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

Thank you for your help!


I'll try that!

When I have a result I post here!


Best regards to everyone,

Ricardo Pereira