How to extract Specific Date using Day of particular Week of a month

Hi,
I couldn’t find this question on the forum.

"I want to extract the date of a particular day of a week of a month.

For ex. I want to extract date of Wednesday of the Third week of Current month. ( Current month is June, 3rd week of Wednesday is 17th)
AND
I want to extract date of Wednesday of the Third week of Previous month.
(Previous Month is May, 3rd week of Wednesday is 13th)

How can we get this date. Please help on this."

Hi Aditya,

There’s no particular function that gives that back, so you have to write your own algorithm. Something like this:

DateofDayWeek(dayoftheweek,numberweek,month):

   FirstDayofMonth = Function_of_theMonth(month)

   DateResult =  FirstDayOfMonth.addDays((numberweek-1)*7+ dayoftheweek-FirstDayofMonth.DayOfWeek)

This is bad pseudo code from my side, but it depends on what information you have and how do you want to give it to your function. Basically you calculate the Date of the First day of the month you want to check and then you add as many days as weeks and adjust for the week day you want and the week day of the first day. Remember that weekday is 0 on a Sunday. Also depends on how do you count the weeks of the month (if the first day of the month is a Sunday for example)