martes, 17 de julio de 2012

Días hábiles entre 2 fechas

Supongamos que tenemos 2 Calendarios.

Dim fecha_inicial As String = Me.Calendar1.SelectedDate '04/07/2012
Dim fecha_final As String = Me.Calendar1.SelectedDate '11/07/2012
Dim dha As Integer = Val(CDate(fecha_final)) - Val(CDate(fecha_inicial))
Dim dias As Integer
Dim x As Integer
For x = 0 To dha - 1
    '6 = sabado
    '7 = domingo
    If Weekday(System.DateTime.FromOADate(CDate(fecha_inicial).ToOADate + x), Microsoft.VisualBasic.FirstDayOfWeek.Monday) <> 6 Or Weekday(System.DateTime.FromOADate(CDate(fecha_inicial).ToOADate + x), Microsoft.VisualBasic.FirstDayOfWeek.Monday) <> 7 Then
        dias = dias + 1
    End If
Next x
MsgBox("Días hábiles: " & dias)

Comparte