# calculate 3rd Monday of Month (example)

I need to be able to automatically calculate the next meeting date for an organization (monthly meetings) that has different groups that meet on specified dates such as the 3rd Monday or the 1st Tuesday. Is there an easy way to do this or a does MBS or Einhugur have this feature?

thanks,

you certainly dont need a plugin to do that !

I think you can set a date as the first day of the month, use https://documentation.xojo.com/index.php/Date.DayOfWeek to check what day of the week is and do some math for the 3rd Monday or 1st Tuesday.

Edit: As you may know, I’m learning Xojo, so I took your information to see if I can find a solution.

For 3rd Monday of the Month:

[code]Listbox1.DeleteAllRows

For i As Integer = 1 To 12
Dim d As New date(2018, i, 1)
Dim dw As Integer = d.dayofweek
Select Case dw
Case 1
Case 2
Case 3
Case 4
Case 5
Case 6
Case 7
End Select
Next
[/code]

For the 1st Tuesday:

[code]Listbox1.DeleteAllRows

For i As Integer = 1 To 12
Dim d As New date(2018, i, 1)
Dim dw As Integer = d.dayofweek
Select Case dw
Case 1
Case 2
Case 3
Case 4
Case 5
Case 6
Case 7
End Select
Next
[/code]

This has not been fully tested… but

``````Public Function Nth_WeekDay_of_Month(byref dt as date,dow as integer,num as integer) as boolean
If dow<1 Or dow>7 Or num<1 Or num>5 Then Return False// illegal request
// find the 1st of the month supplied
dt.day=1
// move to the 1
While dt.DayOfWeek<>dow // 1=Sun 7=Sat
dt.day=dt.day+1
Wend
// date is now the 1st "dow" of the month
If num>1 Then dt.day=dt.day+(num-1)*7
Return True
End Function``````

this should find the Nth DOW of any month

``````dim dt as new date
dim x as boolean
x=Nth_WeekDay_of_Month(dt,2,3) // find 3rd Monday, returned in DT, x=false if bad data``````

Changing my code to use Dave’s function:
For 3rd Monday

``` For i As Integer = 1 To 12 Dim dt As New date(2018, i, 1) Dim x As Boolean x=Nth_WeekDay_of_Month(dt,2,3) if x then listbox1.AddRow(Str(i), Str(dt.day)) Else MsgBox "Check your input" Exit End If Next```

as I like the extend mode, you can use Dave’s method using :

```Public Function Nth_WeekDay_of_Month(extend byref dt as date,dow as integer,num as integer) as boolean ... ```

then use it like :

```dim dt as new date dim x as boolean x=dt.Nth_WeekDay_of_Month(2,3) // find 3rd Monday, returned in DT, x=false if bad data ```

thanks guys, I think I’ve got it…