>The application has to determine how many occurrences of a given day of the week occurred in a given calendar month.
>
>For example- How many Mondays (or any other specified day of the week) were there in February, 2016?
>I can see how to get the answer by looping through all the days in the month in question, but is there a slicker way?
1. Calculate the # of days in the month
2. If #days = 28, answer is 4
3. If #days greater than 28, look at the first ( #days - 28 ) days of the month. If any of those are the one you want, the answer is 5. Otherwise it's 4
i.e. for November (30 days) look at the first ( 30 - 28 ) = 2 days. If you want Mondays, if November 1 or November 2 is a Monday, the answer is 5, otherwise 4.
For February 2016 (29 days), look at the first ( 29 - 28 ) = 1 day. If February 1 is a Monday (and it is), the answer is 5. Any other day of the week the answer is 4.
Regards. Al
"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov
Neither a despot, nor a doormat, be
Every app wants to be a database app when it grows up