Jump to content

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

Recommended Posts

Posted

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?

Posted

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.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.