This is a simple utility to calculate age. e.g, if the age is 4 months then it will display in months, if age is 2 years it will display in years. Example of the DateDiff funtion in VB.
'Just place a command button and text box controls on your form.
'Enter a date of birth in the text box and it will calculate age based on the current date.
Private Sub Command1_Click()
If (Int(DateDiff("y", CDate(Text1.Text), Date)) / 365.25) > 1 Then
MsgBox Round((Int(DateDiff("y", CDate(Text1.Text), Date)) / 365.25)) & " Years"
Else
MsgBox (Mid((Int(DateDiff("y", CDate(Text1.Text), Date)) / 365.25), 1, 3)) * 10 & " Months"
End If
End Sub
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment