Dim age As Integer age = DateDiff("yyyy", txtdatenaisspatient, txtdateconsultation) Dim moispatient As Integer Dim moisdate As Integer Dim jourpatient As Integer Dim jourdate As Integer moispatient = Month(txtdatenaisspatient) jourpatient = Day(txtdatenaisspatient) moisdate = Month(txtdateconsultation) jourdate = Day(txtdateconsultation) If moispatient > moisdate Or (moispatient = moisdate And jourpatient > jourdate) Then age = age - 1 txtagepatient.Text = age Else txtagepatient.Text = age End If
Private Sub Form_Load() Dim dBirth As Date Dim dCompare1 As Date Dim dCompare2 As Date dBirth = CDate("1970-12-30") dCompare1 = CDate(Format$(Date, "YYYY-MM-DD")) dCompare2 = CDate("2010-01-01") Dim iRes1 As Integer Dim iRes2 As Integer iRes1 = GetElapsedYears(dBirth, dCompare1) iRes2 = GetElapsedYears(dBirth, dCompare2) MsgBox "Aujourd'hui, l'utilisateur a " & CStr(iRes1) & " ans." & vbCrLf & _ "Au 1e janvier, il aura " & CStr(iRes2) & " ans." Unload Me End Sub
Private Sub Form_Load() MsgBox Age(#12/31/1983#) End Sub Private Function Age(ByRef vdBirthDate As Date, Optional ByVal vdNow As Date) As Long If vdNow = 0 Then vdNow = Now End If Age = Fix(DateDiff("D", vdBirthDate, vdNow) / 365.25) End Function