Matt Klein Posted November 30, 2002 Posted November 30, 2002 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?
BobWeaver Posted November 30, 2002 Posted November 30, 2002 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.
Recommended Posts
This topic is 8396 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 accountSign in
Already have an account? Sign in here.
Sign In Now