Scusami si ho scritto male, i festivi.
Prova con questa funzione (NumeroGiorniLavorativiDate) a calcolarti quanti giorni lavorativi intercorrono fra la data di inizio e quella che prevedi per la fine (oppure cambiala per tirare fuori la data Feriale in cui devi andare):
PS: attento ai patroni
codice:
Public Function NumeroGiorniLavorativiDate(ByVal DataInizio As Date, ByVal DataFine As Date) As Integer
Dim intGiorni As Integer = 0
Do While DataInizio <= DataFine
If isFestivo(DataInizio.Day, DataInizio.Month) = False Then
intGiorni = intGiorni + 1
End If
DataInizio = DateAdd(DateInterval.Day, 1, DataInizio)
Loop
Return intGiorni
End Function
Public Function isFestivo(ByVal giorno As String, ByVal mese As Integer) As Boolean
Dim appo As DateTime
Dim mess As Boolean
Dim ggPasquetta As Integer
Dim mmPasquetta As Integer
Dim dayPasquetta As String
dayPasquetta = Calcolo_Pasquetta(Year(Now))
mmPasquetta = dayPasquetta.Substring(0, 2)
ggPasquetta = dayPasquetta.Substring(3)
mess = False
If IsDate(giorno.ToString + "/" + mese.ToString + "/" + Year(Date.Now).ToString) Then
appo = giorno.ToString + "/" + mese.ToString + "/" + Year(Date.Now).ToString
If (mmPasquetta = mese And (ggPasquetta = giorno Or ggPasquetta + 1 = giorno)) Or _
(giorno.ToString = 1 And mese.ToString = 1) Or _
(giorno.ToString = 6 And mese.ToString = 1) Or _
(giorno.ToString = 25 And mese.ToString = 4) Or _
(giorno.ToString = 1 And mese.ToString = 5) Or _
(giorno.ToString = 2 And mese.ToString = 6) Or _
(giorno.ToString = 29 And mese.ToString = 6) Or _
(giorno.ToString = 15 And mese.ToString = 8) Or _
(giorno.ToString = 1 And mese.ToString = 11) Or _
(giorno.ToString = 8 And mese.ToString = 12) Or _
(giorno.ToString = 25 And mese.ToString = 12) Or _
(giorno.ToString = 26 And mese.ToString = 12) Or _
appo.DayOfWeek() = DayOfWeek.Saturday Or appo.DayOfWeek() = DayOfWeek.Sunday Then
'è sabato o domenica
mess = True
End If
ElseIf Not IsDate(giorno.ToString + "/" + mese.ToString + "/" + Year(Date.Now).ToString) And _
IsNumeric(giorno) Then
'Non è un giorno facente parte del mese(es: se il mese è di 30 il 31/mese/anno non fa parte del mese)
mess = True
End If
Return mess
End Function
Public Function Calcolo_Pasquetta(ByVal iAnno As Integer) As String
Dim a, b, c, d, e, m, n, giorni As Integer
Dim giorno, mese As String
Select Case iAnno
Case 30 To 1582
m = 15
n = 6
Case 1700 To 1799
m = 23
n = 3
Case 1800 To 1899
m = 23
n = 4
Case 1900 To 2099
m = 24
n = 5
Case 2100 To 2199
m = 24
n = 6
Case 2200 To 2299
m = 25
n = 0
Case 2300 To 2399
m = 26
n = 1
Case 2400 To 2499
m = 25
n = 1
End Select
a = iAnno Mod 4
b = iAnno Mod 7
c = iAnno Mod 19
d = (19 * c + m) Mod 30
e = (2 * a + 4 * b + 6 * d + n) Mod 7
giorni = 22 + d + e
If (giorni <= 31) Then
giorno = giorni
mese = 3
End If
If (giorni = 57 And d = 29 And e = 6) Or (giorni = 56 And c > 10 And d = 28 And e = 6) Then
giorno = giorni - 38
mese = 4
End If
If giorni > 31 Then
giorno = giorni - 31
mese = 4
End If
If (mese.ToString).Length = 1 Then
mese = CType(0, String) + CType(mese, String)
End If
If (giorno.ToString).Length = 1 Then
giorno = "0" + giorno.ToString
End If
Calcolo_Pasquetta = mese & "|" & giorno
End Function