ajetrumpet
Banned
- Local time
- Today, 17:23
- Joined
- Jun 22, 2007
- Messages
- 5,638
Here's a brain teaser for some of you:
I want the easiest possible way to perform the calculation that is in the title of this thread. There is some code in the repository that shows the method that I have as the easiest:
http://www.access-programmers.co.uk/forums/showthread.php?t=132163&highlight=xth
This is very manual, as it checks each day in the relevant week of the month. This is fine and dandy, and is a heck of a lot faster than other methods that I have used, as it only uses two functions per line. However, the method found in the above thread is still redunant, and I have been able to reduce each line in that code to this simple statement (querying for the 3rd Monday in January):
This is the most consolidated version I could get. Here is what I have for finding (as an example) the 3rd Monday in January for any given year:
Is this the best I can do folks? Isn't there anymore consolidation I can do here? I was thinking of nesting a loop inside of an IF statement, but almost positive that kind of method would be slower than the above IIF block. It would certainly be more cumbersome to sift through in the modules anyway. And for that reason alone, I don't want to do it....
Thanks for any input you guys!
I want the easiest possible way to perform the calculation that is in the title of this thread. There is some code in the repository that shows the method that I have as the easiest:
http://www.access-programmers.co.uk/forums/showthread.php?t=132163&highlight=xth
This is very manual, as it checks each day in the relevant week of the month. This is fine and dandy, and is a heck of a lot faster than other methods that I have used, as it only uses two functions per line. However, the method found in the above thread is still redunant, and I have been able to reduce each line in that code to this simple statement (querying for the 3rd Monday in January):
Code:
Weekday("1/15/" & DatePart("yyyy", MyDate)) = 2
Code:
3rd Monday =
IIf(Weekday("1/15/" & DatePart("yyyy", InputDate)) = 2, _
"1/15/" & DatePart("yyyy", InputDate), _
IIf(Weekday("1/16/" & DatePart("yyyy", InputDate)) = 2, _
"1/16/" & DatePart("yyyy", InputDate), _
IIf(Weekday("1/17/" & DatePart("yyyy", InputDate)) = 2, _
"1/17/" & DatePart("yyyy", InputDate), _
IIf(Weekday("1/18/" & DatePart("yyyy", InputDate)) = 2, _
"1/18/" & DatePart("yyyy", InputDate), _
IIf(Weekday("1/19/" & DatePart("yyyy", InputDate)) = 2, _
"1/19/" & DatePart("yyyy", InputDate), _
IIf(Weekday("1/20/" & DatePart("yyyy", InputDate)) = 2, _
"1/20/" & DatePart("yyyy", InputDate), _
IIf(Weekday("1/21/" & DatePart("yyyy", InputDate)) = 2, _
"1/21/" & DatePart("yyyy", InputDate), 0))))))))
Thanks for any input you guys!
Last edited: