25
Views
4
Comments
Solved
Calculating workdays for every month
Application Type
Reactive

Hi Folks,

We recently received a client requirement to enhance an existing timer that runs daily. The enhancement involves stopping the timer from running between the 5th and 15th workdays of each month (workdays consider from Monday to Friday). Since the workdays vary each month, we need to dynamically calculate these dates at the start of every month.

If the dates were fixed, we could simply write a condition to control the timer. However, with varying dates each month, we need a different approach. How can we implement this logic to meet the client's requirement? 

It would be grateful to me if you could let me know if there are any Forge components, documentation available within Out Systems that match my requirements. 

Thank you in advance for your valuable thoughts and answers! 


2016-04-22 00-29-45
Nuno Reis
 
MVP
Solution

Hello.

There are two ways.


In pure OutSystems:

You could generate first of the month, increment until today and count all non-weekends.


In SQL:

Same thing. You generate all days between first of month and today. Select all the non-weekends and count them.


WITH DateSeries AS (
    SELECT CAST(DATEADD(DAY, 1 - DAY(@Today), @Today) AS DATE) AS DateValue
    UNION ALL
    SELECT DATEADD(DAY, 1, DateValue)
    FROM DateSeries
    WHERE DateValue < @Today
)
SELECT count(datevalue)
FROM DateSeries
where datepart(weekday,datevalue) not in (1,7)


You can go either way. 

SQL may be prettier as it is only one visual element, but you need to create the output structure for the Integer.

2026-03-06 05-43-38
Sai Raj Goru

Hi @Nuno Reis,

Thank you for your valuable solutions. They are pretty straightforward and easy to implement. I appreciate the information provided. Additionally, I would like to extend my heartfelt thanks to @Mihai Melencu and @Beatriz Sabino for their wonderful suggestions and references, which have greatly enhanced my understanding.

2022-12-22 10-00-39
Beatriz Sabino

Hi Goru,

There have been several posts about this topics. Here are a few that I found:

- Post 1

Post 2

- Post 3

There are also a few forge components that might help, such as this one.

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

Hi @Goru ,

You can use CurrDate() and the DayOfWeek() function to determine if the current day is a workday. Why do you need to calculate the dates at the start of each month? You can add a validation at the start of the timer to check if the current day is between 5 and 15 and if it's a work day.

DayOfWeek(CurrDate())


2016-04-22 00-29-45
Nuno Reis
 
MVP
Solution

Hello.

There are two ways.


In pure OutSystems:

You could generate first of the month, increment until today and count all non-weekends.


In SQL:

Same thing. You generate all days between first of month and today. Select all the non-weekends and count them.


WITH DateSeries AS (
    SELECT CAST(DATEADD(DAY, 1 - DAY(@Today), @Today) AS DATE) AS DateValue
    UNION ALL
    SELECT DATEADD(DAY, 1, DateValue)
    FROM DateSeries
    WHERE DateValue < @Today
)
SELECT count(datevalue)
FROM DateSeries
where datepart(weekday,datevalue) not in (1,7)


You can go either way. 

SQL may be prettier as it is only one visual element, but you need to create the output structure for the Integer.

2026-03-06 05-43-38
Sai Raj Goru

Hi @Nuno Reis,

Thank you for your valuable solutions. They are pretty straightforward and easy to implement. I appreciate the information provided. Additionally, I would like to extend my heartfelt thanks to @Mihai Melencu and @Beatriz Sabino for their wonderful suggestions and references, which have greatly enhanced my understanding.

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