SOLVED: Check if a Date is on the Weekend & Skip
Hello, I have a script that needs to only carry out and action if the day is not a weekend. Could somebody assist with this code?
Code:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'convert date1 to a string
Dim StartDate As Date = DateTimePicker1.Value
Dim StartDateStr As String
'get date2
Dim EndDate As Date = DateTimePicker2.Value
'get the number of days between date1 and date2
Dim intDays As Integer = EndDate.Subtract(StartDate).Days()
Dim i As Integer
For i = 0 To intDays
'Check If StartDate is a not a weekend
'if it is not a weekend
'Do code
Else
EndIf
StartDate = StartDate.Date.AddDays(1D)
Next
End Sub
Re: Check if a Date is on the Weekend & Skip
Code:
Dim dt As DateTime = DateTime.Now
If Not (dt.DayOfWeek = DayOfWeek.Saturday OrElse dt.DayOfWeek = DayOfWeek.Sunday) Then
'not sat or sun
End If
Re: Check if a Date is on the Weekend & Skip
You can look at DayOfWeek() that will give you a number from 0 to 6
Re: Check if a Date is on the Weekend & Skip
Thank you, geniuses! :thumb: