- '===============================
- 'Code à ajouter dans un module '
- 'Convertion texte en date date '
- 'P. Marchand le 07/03/2007 '
- '===============================
-
- Function StringDate(Fdate As Variant) As String
- Dim JJDate, MMDate, YYDate As String
- On Error GoTo Erreur_Saisie
-
- ' control du nombre d'argument date (010101) au minimum pour le 01/01/2001
- If Len(Trim(Fdate)) < 6 Then GoTo Erreur_Saisie
-
- 'si il n'y a pas de "/" et que la longeure est comprise entre 6 et 8
- If (InStr(1, Fdate, "/") = 0 And (Len(Trim(Fdate)) = 6 Or Len(Trim(Fdate)) = 8)) Then
- JJDate = Trim(Left(Fdate, 2))
- MMDate = Trim(Right(Left(Fdate, 4), 2))
- If Len(Trim(Fdate)) = 6 Then YYDate = Trim(Right(Left(Fdate, 6), 2))
- If Len(Trim(Fdate)) = 8 Then YYDate = Trim(Right(Left(Fdate, 8), 4))
- StringDate = Format(JJDate & "/" & MMDate & "/" & YYDate, "DD/MM/YYYY")
- Exit Function
- Else
- StringDate = Format(Fdate, "DD/MM/YYYY")
- Exit Function
- End If
-
- Erreur_Saisie:
- MsgBox "Erreure de saisie !) : exit funtion"
-
- End Function
'===============================
'Code à ajouter dans un module '
'Convertion texte en date date '
'P. Marchand le 07/03/2007 '
'===============================
Function StringDate(Fdate As Variant) As String
Dim JJDate, MMDate, YYDate As String
On Error GoTo Erreur_Saisie
' control du nombre d'argument date (010101) au minimum pour le 01/01/2001
If Len(Trim(Fdate)) < 6 Then GoTo Erreur_Saisie
'si il n'y a pas de "/" et que la longeure est comprise entre 6 et 8
If (InStr(1, Fdate, "/") = 0 And (Len(Trim(Fdate)) = 6 Or Len(Trim(Fdate)) = 8)) Then
JJDate = Trim(Left(Fdate, 2))
MMDate = Trim(Right(Left(Fdate, 4), 2))
If Len(Trim(Fdate)) = 6 Then YYDate = Trim(Right(Left(Fdate, 6), 2))
If Len(Trim(Fdate)) = 8 Then YYDate = Trim(Right(Left(Fdate, 8), 4))
StringDate = Format(JJDate & "/" & MMDate & "/" & YYDate, "DD/MM/YYYY")
Exit Function
Else
StringDate = Format(Fdate, "DD/MM/YYYY")
Exit Function
End If
Erreur_Saisie:
MsgBox "Erreure de saisie !) : exit funtion"
End Function