I tried to find out the Thursday of every week. It giving the right output if the current day is less than Thursday. And it gives wrong output if we are on Friday & Saturday.
Private Function GetNextDate(day As DayOfWeek) As DateTime
Dim now As DateTime = DateTime.Today
Dim today As Integer = CInt(now.DayOfWeek)
Dim find As Integer = CInt(day)
Dim delta As Integer = find - today
If delta > 0 Then
Return now.AddDays(delta)
Else
Return now.AddDays(7 - delta)
End If
End Function
' For output
Dim comingThursday = GetNextDate(DayOfWeek.Thursday)
MsgBox(comingThursday.ToString)
Please help me out to find out the coming Thursday date properly. Or suggest me any other better way to find out.
Your
deltavariable will be negative when the day you request (Thursday) is before the current day (Friday or Saturday) of the week. You therefore have to add it to 7, not subtract it: