I have a DateTimePicker that will restrict the user from selecting weekends, but I am not sure how to limit the picker to only certain hours of the day as well. I have tried using .AddHours(12) but that could put the time at 4-5am which is outside of the window I'm trying to adhere to.
I'm trying to limit the selection between 8a-4p local time.
Any assistance would be appreciated.
Private Sub DateTimePick_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePick.ValueChanged
If (DateTimePick.Value.DayOfWeek = DayOfWeek.Saturday) Or (DateTimePick.Value.DayOfWeek = DayOfWeek.Sunday) Then
'Now just add the right amount of days to make it Monday
Select Case DateTimePick.Value.DayOfWeek
Case DayOfWeek.Saturday
DateTimePick.Value = DateTimePick.Value.AddDays(2)
Case DayOfWeek.Sunday
DateTimePick.Value = DateTimePick.Value.AddDays(1)
End Select
MsgBox("We're sorry, we are not currently scheduling maintenance for Saturday or Sunday. The following Monday, " &
DateTimePick.Value.ToShortDateString & ", has been selected.",
MsgBoxStyle.Exclamation, "Invalid selection")
End If
End Sub