In my web form, I am trying to figure out the number of days off not including the weekend and holidays. I have a SQL database where the holiday date is in date format (yyyy-MM-dd). The user adds dates using the format MM/dd/yyyy. Not counting weekend part of my code works. Figuring out if a date is a holiday, and if it is, not counting it does not work. Here is my code. I've tried everything that is remarked out. I appreciate any help to figure out how to compare the entered date with the SQL date.
Dim intCount As Integer
Dim temp As Integer
'Set same day as 1 <-- your preference. Though you can't work out averages if they are 0.
'Im not checking if this day is a holiday (though in theory you shouldn't have to!).
If StartDate = EndDate Then
WorkingDays = 1 'Change me to your needs.
Exit Function
End If
intCount = 0 ' Now we start counting days. 'If you always want to count the first day, set this to 1.
Do Until StartDate = EndDate
'First, we find out if this day is a weekday or a weekend.
'If weekday, 1 gets added to the number of days.
Select Case Weekday(StartDate)
Case Is = 1, 7
intCount = intCount 'Weekend, so nothing added.
Case Else
intCount = intCount + 1
End Select
'Now, if this day was a holiday, we take it back off again!
'Dim vsqldate = DateTime.ParseExact(StartDate, "yyyy-MM-dd", Nothing)
'Dim vsqldate = StartDate.ToString("yyyy-MM-dd")
'Dim vsqldate = fromDt.ToString("yyyy-MM-dd")
Dim vsqldate = CDate(Format(StartDate, "yyyy-MM-dd"))
Dim strWhere = "Holiday= #" & vsqldate & "#" 'change fieldname.
If (DCount("Holiday", "tblCodesholidays", strWhere) > 0) Then 'Change to your field/table names.
intCount = intCount - 1
End If
StartDate = StartDate.AddDays(1) 'We move to the next day.
Loop
WorkingDays = intCount