[RESOLVED] calculationg age from date to date (not today/now value)
I'm trying to make a program for the school i work for, which calculate students age according to a certian date in years, months and days
the program is for use at the school to calculate students ages in order to know they are applicable to which grade at the official date of the new academic year
i.e. calculating if student's date birth was @ 1/1/2000 so i wanna know how many years, months, n days he is @ 1/10/2009
im kinda new in the VB world n the programming world, but i searched the forum n found many results but it seemed they didnt worked correctly for my case
i tried using dtpicker or entering the date manually in a textbox but i prefer using the dtpicker
please give me an example how to make it, which function better to be used in such case
Re: calculationg age from date to date (not today/now value)
perhaps something like this?
Code:
Dim bday As Date, target As Date
Dim numMo As Integer, numYrs As Integer, numDays As Integer
Dim tmpDate As Date
bday = CDate("1/1/2000")
target = CDate("1/10/2009")
If target <= bday Then
MsgBox "Dates aren't Valid"
Exit Sub 'or function
End If
numYrs = DateDiff("yyyy", bday, target)
tmpDate = DateAdd("yyyy", numYrs, bday)
If tmpDate > target Then
numYrs = numYrs - 1
tmpDate = DateAdd("yyyy", -1, tmpDate)
End If
numMo = DateDiff("m", tmpDate, target)
tmpDate = DateAdd("m", numMo, tmpDate)
If tmpDate > target Then
numMo = numMo - 1
tmpDate = DateAdd("m", -1, tmpDate)
End If
numDays = DateDiff("d", tmpDate, target)
MsgBox "Years=" & numYrs & " Months=" & numMo & " Days=" & numDays
Last edited by technorobbo; Aug 26th, 2009 at 05:35 AM.
Re: calculationg age from date to date (not today/now value)
herewith i attached a project, which calculate year, month and days with datepicker
hope this is what u need, if ur problm solved pls mark this thread as resolved
thank u
Last edited by seenu_1st; Aug 26th, 2009 at 05:31 AM.
Re: calculationg age from date to date (not today/now value)
thank you all for your useful replies
that code provided by techno was ideal to me
i had just to change the date n put the dtpicker's value instead
n puted it all under a command button and replacing the msgbox with 3 textboxes