Sub test2()
Dim a, forme$, x As Boolean, dat As Date, T$, AA$, timeval
'a = "20-mars-2020 20:52:32"
'a = "vendredi 20-décembre-2020 20:52:32"
a = "vendredi 20-décembre-2020 20:52"
'a = "vend 20-décembre-2020 20:52"
'a = "ven. 20-mars-2020 20:52:32"
'a = "20 mars 2020 20:52:32"
'a = "20/03/2020 20:52:32"
'a = "20/03/2020"
AA = a
x = GetDateFormat(a, dat, timeval, forme)
If x = True Then
T = AA & vbCrLf & "-----------------------" & vbCrLf
T = T & "date : " & CStr(x) & vbCrLf
T = T & "date : " & Format(dat, "dd/mm/yyyy") & vbCrLf
T = T & "time value : " & timeval & vbCrLf
T = T & "format :" & forme & vbCrLf
MsgBox T
Else
End If
End Sub
Function GetDateFormat(a, dat, timeval, forme)
forme = ""
If Not IsDate(a) Then 'si jour en lettre(abrégé ou complet)
If Not IsNumeric(Left(a, 3)) Then ddd = "ddd ": b = Mid(a, InStr(1, a, " ") + 1)
If Not IsNumeric(Left(a, 5)) And Not Left(a, 5) Like "*.*" Then ddd = "ddddd ": b = Mid(a, InStr(1, a, " ") + 1)
If Not IsNumeric(Left(a, 5)) And Left(a, 5) Like "*.*" Then ddd = "ddd. ": b = Mid(a, InStr(1, a, " ") + 1)
If Not IsNumeric(Left(a, 5)) And Left(a, 5) Like "* *" Then ddd = "ddd ": b = Mid(a, InStr(1, a, " ") + 1)
If b <> "" Then a = b
End If
If IsDate(a) Then
Select Case True
'test format jour mois en lettre complet année
Case Format(a, "dd mmmm yyyy") = a: a = CDate(a): forme = "dd mmmm yyyy"
Case Format(a, "dd-mmmm-yyyy") = a: a = CDate(a): forme = "dd-mmmm-yyyy"
Case Format(a, "dd/mmmm/yyyy") = a: a = CDate(a): forme = "dd-mmmm-yyyy"
Case Format(a, "dd.mmmm.yyyy") = a: a = CDate(a): forme = "dd.mmmm.yyyy"
'test format jour mois en lettre abrégé année
Case Format(a, "dd mmm yyyy") = a: a = CDate(a): forme = "dd mmm yyyy"
Case Format(a, "dd-mmm-yyyy") = a: a = CDate(a): forme = "dd-mmm-yyyy"
Case Format(a, "dd/mmm/yyyy") = a: a = CDate(a): forme = "dd/mmm/yyyy"
Case Format(a, "dd.mmm.yyyy") = a: a = CDate(a): forme = "dd.mmm.yyyy"
'test format jour mois en lettre complet année heure minute
Case Format(a, "dd.mmmm.yyyy hh:nn") = a: forme = "dd.mmmm.yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd-mmmm-yyyy hh:nn") = a: forme = "dd-mmmm-yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd/mmmm/yyyy hh:nn") = a: forme = "dd.mmmm.yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd mmmm yyyy hh:nn") = a: forme = "dd mmmm yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
'test format jour mois en lettre complet année heure minute seconde
Case Format(a, "dd mmmm yyyy hh:nn:ss") = a: forme = "dd mmmm yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd-mmmm-yyyy hh:nn:ss") = a: forme = "dd-mmmm-yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd/mmmm/yyyy hh:nn:ss") = a: forme = "dd/mmmm/yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd.mmmm.yyyy hh:nn:ss") = a: forme = "dd.mmmm.yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
'test format jour mois en lettre abrégé année heure minute
Case Format(a, "dd mmm yyyy hh:nn") = a: forme = "dd mmm yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd-mmm-yyyy hh:nn") = a: forme = "dd-mmm-yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd.mmm.yyyy hh:nn") = a: forme = "dd.mmm.yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd/mmm/yyyy hh:nn") = a: forme = "dd/mmm/yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
'test format jour mois en lettre abrégé année heure minute seconde
Case Format(a, "dd mmm yyyy hh:nn:ss") = a: forme = "dd mmm yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd-mmm-yyyy hh:nn:ss") = a: forme = "dd-mmm-yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd.mmm.yyyy hh:nn:ss") = a: forme = "dd.mmm.yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd/mmm/yyyy hh:nn:ss") = a: forme = "dd/mmm/yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
'test format jour mois en numeric année heure minute
Case Format(a, "dd mm yyyy hh:nn") = a: forme = "dd mm yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd/mm/yyyy hh:nn") = a: forme = "dd/mm/yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd-mm-yyyy hh:nn") = a: forme = "dd-mm-yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd.mm.yyyy hh:nn") = a: forme = "dd.mm.yyyy hh:mm": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
'test format jour mois en lnumeric année heure minute seconde
Case Format(a, "dd mm yyyy hh:nn:ss") = a: forme = "dd mm yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd/mm/yyyy hh:nn:ss") = a: forme = "dd/mm/yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd-mm-yyyy hh:nn:ss") = a: forme = "dd-mm-yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
Case Format(a, "dd.mm.yyyy hh:nn:ss") = a: forme = "dd.mm.yyyy hh:mm:ss": a = DateValue(a) + TimeValue(a): timeval = TimeValue(a)
'format classique les plus courants
Case Format(a, "dd/mm/yyyy") = a: forme = "dd/mm/yyyy": a = DateValue(a): ddd = ""
Case Format(a, "dd-mm-yyyy") = a: forme = "dd-mm-yyyy": a = DateValue(a): ddd = ""
Case Format(a, "dd mm yyyy") = a: forme = "dd mm yyyy": a = DateValue(a): ddd = ""
Case Format(a, "dd.mm.yyyy") = a: forme = "dd.mm.yyyy": a = DateValue(a): ddd = ""
'test format jour mois année en 2 digits
Case Format(a, "dd/mm/yy") = a: forme = "dd/mm/yy": a = DateValue(a): ddd = ""
Case Format(a, "dd-mm-yy") = a: forme = "dd-mm-yy": a = DateValue(a): ddd = ""
Case Format(a, "dd mm yy") = a: forme = "dd mm yy": a = DateValue(a): ddd = ""
Case Format(a, "dd.mm.yy") = a: forme = "dd.mm.yy": a = DateValue(a): ddd = ""
'etc....
End Select
End If
dat = a
forme = ddd & forme
GetDateFormat = IsDate(a)
End Function