If Year(dat2) > 9999 Or Year(dat1) < 1700 Then ...
yeardécalée = 2000
If dat1 < CDate("09/12/1760") Then dat1 = dat1 - 11
If dat1 <= CDate("09/12/1582") Then dat1 = dat1 + 10
If dat2 <= CDate("09/12/1582") Then dat2 = dat2 + 10
Function DATEDIFF_AMJ5$(ByVal dat1 As Date, Optional ByVal dat2 As Date = 0, Optional JustYear As Boolean = False)
'**************************************
'fonction DateDiff_AMJ V°5 temporaire
'auteur:patricktoulon avec Eriiic sur Exceldownloads
'date 05/07/2021
'*************************************
Dim A$, M$, J$, Dtemp$, et$, yeardécalée&, y
If dat2 = 0 Then dat2 = Date
If dat1 > dat2 Then Dtemp = dat2: dat2 = dat1: dat1 = Dtemp
If Month(dat1) = 12 And Day(dat1) <= 9 And Year(dat1) <= 1562 Then dat1 = dat1 + 10
If Month(dat2) = 12 And Day(dat2) <= 9 And Year(dat2) <= 1562 Then dat2 = dat2 + 10
dat1 = DateSerial(Year(dat1) + 2000, Month(dat1), Day(dat1))
dat2 = DateSerial(Year(dat2) + 2000, Month(dat2), Day(dat2))
A = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""y"")")
M = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""ym"")")
J = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""md"")")
A = IIf(A = 0, "", IIf(A = 1, A & " an", A & " ans"))
M = IIf(M = 0, "", IIf(M >= 1, IIf(Val(J) = 0, " et ", "") & M & " mois", M & " mois"))
J = IIf(J = 0, "", IIf(J = 1, "1 jour", J & " jours"))
et = IIf(Val(A) > 0 Or Val(M) > 0, IIf(Val(J) > 0, " et ", " "), "")
DATEDIFF_AMJ5 = Application.Trim(A & IIf(Not JustYear, " " & M & " " & et & J, ""))
End Function
Function DATEDIFF_AMJ5$(ByVal dat1 As Date, Optional ByVal dat2 As Date = 0, Optional JustYear As Boolean = False)
'**************************************
'fonction DateDiffAMJ V°5
'auteur:patricktoulon avec Eriiic sur Exceldownloads
'date de mise en jour V°4:04/07/2021
' mise a jour supplementaire
' ajout de l'argument boolean "JustYear" pour ne récuprérer que les années
'*************************************
Dim A$, M$, J$, Dtemp$, et$, yeardécalée&, y
If dat2 = 0 Then dat2 = Date
If dat1 > dat2 Then Dtemp = dat2: dat2 = dat1: dat1 = Dtemp
'If Month(dat1) = 12 And Day(dat1) <= 9 And Year(dat1) <= 1562 Then dat1 = dat1 + 10
'If Month(dat2) = 12 And Day(dat2) <= 9 And Year(dat2) <= 1562 Then dat2 = dat2 + 10
If dat1 <= CDate("10/12/1562") Then dat1 = dat1 + 10
If dat2 <= CDate("10/12/1562") Then dat2 = dat2 + 10
dat1 = DateSerial(Year(dat1) + 2000, Month(dat1), Day(dat1))
dat2 = DateSerial(Year(dat2) + 2000, Month(dat2), Day(dat2))
A = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""y"")")
M = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""ym"")")
J = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""md"")")
A = IIf(A = 0, "", IIf(A = 1, A & " an", A & " ans"))
M = IIf(M = 0, "", IIf(M >= 1, IIf(Val(J) = 0, " et ", "") & M & " mois", M & " mois"))
J = IIf(J = 0, "", IIf(J = 1, "1 jour", J & " jours"))
et = IIf(Val(A) > 0 Or Val(M) > 0, IIf(Val(J) > 0, " et ", " "), "")
DATEDIFF_AMJ5 = Application.Trim(A & IIf(Not JustYear, " " & M & " " & et & J, ""))
End Function
If dat1 <= CDate("10/12/1562") Then dat1 = dat1 + 10
Const year400 As Long = 2000
Function DATEDIFF_AMJ5$(ByVal dat1 As Date, Optional ByVal dat2 As Date = 0, Optional JustYear As Boolean = False)
'**************************************
'fonction DateDiffAMJ V°5
'auteur:patricktoulon avec Eriiic sur Exceldownloads
'date de mise en jour V°4:04/07/2021
' mise a jour supplementaire
' ajout de l'argument boolean "JustYear" pour ne récuprérer que les années
'*************************************
Dim A$, M$, J$, Dtemp$, et$, yeardécalée&, y
If dat2 = 0 Then dat2 = Date
If dat1 > dat2 Then Dtemp = dat2: dat2 = dat1: dat1 = Dtemp
If dat1 <= CDate("10/12/1582") Then dat1 = dat1 + IIf(Month(dat1) > 11, 10, 1)
If dat2 <= CDate("10/12/1582") Then dat2 = dat2 + IIf(Month(dat1) > 11, 10, 1)
If dat2 > CDate("09/12/1582") And dat2 < CDate("31/12/1582") Then dat2 = dat2 + IIf(Month(dat1) = 12, -10, 1)
dat1 = DateSerial(Year(dat1) + year400, Month(dat1), Day(dat1))
dat2 = DateSerial(Year(dat2) + year400, Month(dat2), Day(dat2))
A = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""y"")")
M = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""ym"")")
J = Evaluate("=DATEDIF(" & CLng(dat1) & "," & CLng(dat2) & ",""md"")")
A = IIf(A = 0, "", IIf(A = 1, A & " an", A & " ans"))
M = IIf(M = 0, "", IIf(M >= 1, M & " mois", M & " mois"))
J = IIf(J = 0, "", IIf(J = 1, "1 jour", J & " jours"))
et = IIf(Val(A) > 0 Or Val(M) > 0, IIf(Val(J) > 0, " et ", " "), "")
DATEDIFF_AMJ5 = Application.Trim(A & IIf(Not JustYear, " " & M & " " & et & J, ""))
End Function
30/11/1562 | 01/01/1563 | 22 jours |
30/11/1562 | 01/01/1563 | 1 mois |