1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| strDateSaisie = InputBox("Entrez une date : ","Date","AAAA-MM-JJ")
If strDateSaisie <> "" Then MsgBox "[" & strDateSaisie & "] : " & IsValidDate(strDateSaisie)
'==========================
Function Bissextile(An)
Bissextile = (An Mod 4 = 0 And An Mod 100 <> 0) Or (An Mod 400 = 0)
End Function
' =========================
Function IsValidDate(sDate)
Const Msg = "Date valide", Msg1 = "Date non valide"
Dim Ret, tb
tb = Split(sDate, "-")
If Ubound(tb) = 2 and isNumeric(join(tb,"")) Then
If CInt(tb(0)) < 1900 Or CInt(tb(0)) > 2100 Then Ret = Msg1
If CInt(tb(1)) < 1 Or CInt(tb(1)) > 12 Then Ret = Msg1
End If
Select case CInt(tb(1))
Case 1,3,5,7,8,10,12
If CInt(tb(2))<=31 Then
Ret = Msg
Else :Ret = Msg1
End If
Case 4,6,9,11
If CInt(tb(2))<=30 Then
Ret = Msg
Else :Ret = Msg1
End If
Case 2
If Bissextile(tb(0)) Then
If CInt(tb(2))<=29 Then
Ret = Msg
Else :Ret = Msg1
End If
Else
If CInt(tb(2))<=28 Then
Ret = Msg
Else :Ret = Msg1
End If
End If
End Select
IsValidDate = Ret
End Function |
Partager