Find The Date Of The First Instance Of A Weekday In A Month

Published: {ts '2012-09-18 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/find-the-date-of-the-first-instance-of-a-weekday-in-a-month/

As a follow up on my previous post on calculating week numbers for a month, today I am going to show how to work out the first date in a month that a given weekday occurs on.

Again this is useful when dealing with financial reporting tools where you might need to find the first wednesday of this month. You can then extrapolate out the 2nd 3rd 4th instances for the same weekday.

I think the comments explain the logic fairly well so I wont go pulling it apart. If you have a question please leave a comment and I'll try answer as best I can. Oh and yeah I know the function name is very verbose but that is just to help explain what it is going on here, feel free to shorten it.