# Number of Mondays in a given Month....

This topic is 7802 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

Does anyone know a good way to get a total of the number that a certain day(ie. Monday) of the week occurs in a given month? In otherwords, how many mondays in the month of September 2002.

I can think of several ways to get the result, but they are neither elegant nor efficient and involve several different fields or scripts. There's bound to be a elegant calculation for this. Anyone?

##### Share on other sites

The general formula for counting specific weekdays over any arbitrary period is:

Int((EndDate-StartDate)/7) +( Mod(EndDate-StartDate, 7) >= Mod(7+QueryDay-DayofWeek(StartDate), 7))

QueryDay is an integer 1..7 representing the day of week you want to count Sunday is 1, Monday is 2, Saturday is 7 etc.

StartDate and EndDate define the period over which you want to count. So, for a particular month you could calculate StartDate as:

Date(QueryMonth,1,QueryYear)

and EndDate as:

Date(QueryMonth+1,1,QueryYear)-1

where QueryMonth and QueryYear are the month and year you are interested in.

##### Share on other sites

Thanks Bob. That does the trick.

##### Share on other sites

This topic is 7802 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account

×
×
• Create New...