1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| Private Sub Command1_Click()
MsgBox Age(DateValue(datenais.Text), DateValue(Now))
End Sub
Public Function Age(D1 As Date, D2 As Date) As String
Dim nba As Integer, nbm As Integer, nbj As Integer
Dim LaFeinte As Long ' <<======= et.... pour une feinte, ... tu vas voir...
If D1 > D2 Then
Age = "La 2ème date doit nécessairement être plus grande que la 1ère !"
Exit Function
End If
LaFeinte = IIf(Day(D2) < Day(D1), 1, 0) ' retournera 1 si Day(D2) < Day(D1) sinon 0
nba = Year(D2) - Year(D1) - Switch(Month(D2) < Month(D1), 1, Month(D2) = Month(D1), LaFeinte, True, 0)
nbm = (Month(D2) - Month(D1) - LaFeinte + 12) Mod 12 ' <<<==== ...Hé hé !......(zi rigoule)...
nbj = Day(D2) - Day(D1) + LaFeinte * Day(DateSerial(Year(D2), Month(D2), 1) - 1)
Age = Trim(IIf(nba > 0, nba & " an" & IIf(nba > 1, "s", "") & " ", "") & _
IIf(nbm > 0, nbm & " mois ", "") & IIf((nbj > 0) Or (nba + nbm = 0), nbj & " jour" & IIf(nbj > 1, "s", ""), ""))
End Function |
Partager