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,
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
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
Thank You!
Can You explain to me where I can build this extension?
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.
Thank you for your help!
I'll try that!
When I have a result I post here!
Best regards to everyone,
Ricardo Pereira wrote:
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..
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.
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.
Hi Anqi
PFA module which contains logic to calculate working days between 2 dates.
Thanks and Regards,
Suraj Borade
Suraj Borade wrote:
Hi Suraj,
I made some changes for my use case, but your oml helped me a lot.
Thank you!
Ana Dias wrote:
Your Welcome Ana..!! :)
Very usefel, many thanks
Hi Edwardo,
Did you see Suraj's post? It contains an example Module.
Kilian Hekhuis wrote:
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 ??
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.
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!
But this is all really basic programming, you should be able to figure this out yourself!Okee
Thank youuu sir :))
As discussed in PM, here's an example.
Hwaa.. Thank's Sir.
You're most welcome. And more importantly, please try to understand the code, rather than copy/paste it ;).