Reputation: 83
I'm trying compute the dates of Due date into Date Returned. And if the date return pass the due date in one day. there will be a fine.
This is my code in computation
Dim st As Integer = MetroDateTime1.Value.Date.Subtract(Label9.Text).Days
If (Label6.Text) > (MetroDateTime1.Value.Date) Then _
MessageBox.Show("Date return must not below to date borrowed", _
"Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
MetroDateTime1.Focus()
ElseIf (st > 0) Then
MetroTextBox7.Text = (st * 5).ToString()
Else
MetroTextBox7.Text = 0
End If
'Metrotextbox7 is the textbox for fines. But, how to compute the dates excluding the weekends?
Upvotes: 2
Views: 3166
Reputation: 1705
'get business Days
Public Shared Function GetBusinessDays(startDay As DateTime, endDay As DateTime) As Integer
Dim today = Date.Today
Dim weekend = {DayOfWeek.Saturday, DayOfWeek.Sunday}
Dim businessDays =
From d In Enumerable.Range(0, (endDay.Date - startDay.Date).Days + 1)
Select day = today.AddDays(d)
Where Not weekend.Contains(day.DayOfWeek)
Return businessDays.Count()
End Function
Upvotes: 1