Function Datediff_AMJ$(ByVal dat1, Optional ByVal dat2 = 0)
Dim a%, m%, j%, dtemp As Date, Erreur$
If dat2 = 0 Then dat2 = Date
Erreur = IIf(Not IsDate(dat1), "(1)", ""): Erreur = Erreur & IIf(Not IsDate(dat2), "(2)", ""): Erreur = IIf(Erreur <> "", "Invalid Argmt(" & Erreur & ")", "")
If Erreur <> "" Then Datediff_AMJ = Erreur: Exit Function
dat1 = CDate(dat1): dat2 = CDate(dat2)
If dat1 > dat2 Then dtemp = dat1: dat1 = dat2: dat2 = dtemp
a = Evaluate("DATEDIF(" & CDbl(dat1) & "," & CDbl(dat2) & ",""y"")")
m = Evaluate("DATEDIF(" & CDbl(dat1) & "," & CDbl(dat2) & ",""ym"")")
j = Abs(DateSerial(Year(dat1) + a, Month(dat1) + m, Day(dat1)) - dat2)
Datediff_AMJ = RTrim(IIf(a, a & " an" & IIf(a = 1, " ", "s "), "") & IIf(m, m & " mois ", "") & IIf(j, j & " jour" & IIf(j = 1, "", "s"), ""))
End Function
Sub test()
MsgBox Datediff_AMJ("02/02/2020", "25/01/2017")
MsgBox Datediff_AMJ("25/01/2017", "02/02/2020")
MsgBox Datediff_AMJ("04/03/1970")
MsgBox Datediff_AMJ("toto", "titi")
MsgBox Datediff_AMJ("25/04/2016", "titi")
End Sub