hi,
i think that i will found the answer in the net but i dont.
the function dateDiff its accurate? i meen that calculate all month with 30 days or it do the abbservation with 28 days month and 31 days?
thank you!!!
miki
hi,
i think that i will found the answer in the net but i dont.
the function dateDiff its accurate? i meen that calculate all month with 30 days or it do the abbservation with 28 days month and 31 days?
thank you!!!
miki
What exactly is your question? If you need info on Datediff() see http://www.techonthenet.com/access/f...e/datediff.php
If you need a function to calculate Age, here's one
and a routine for testingCode:'--------------------------------------------------------------------------------------- ' Procedure : Age ' Author : Jack (from awf) ' Date : 06-09-2012 ' Purpose : This routine determines the Age of a Person given their DOB. ' It accounts for the birthday this year (whether passed or not). A second parameter ' Specdate allows you to work from a different Date than today's date. 'If SpecDate is missing, the routine defaults to today's date. '--------------------------------------------------------------------------------------- ' Last Modified: ' ' Inputs: N/A ' Dependency: N/A '-------------------------------------------------------------------------- ' Public Function Age(dteDOB As Date, Optional SpecDate As Variant) As Integer Dim dteBase As Date, intCurrent As Date, intEstAge As Integer 10 On Error GoTo Age_Error 20 If IsMissing(SpecDate) Then 30 dteBase = Date 40 Else 50 dteBase = SpecDate 60 End If 70 intEstAge = DateDiff("yyyy", dteDOB, dteBase) 80 intCurrent = DateSerial(Year(dteBase), Month(dteDOB), Day(dteDOB)) 90 Age = intEstAge + (dteBase < intCurrent) 100 On Error GoTo 0 110 Exit Function Age_Error: 120 MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure Age of Module AWF_Related" End Function
Code:'--------------------------------------------------------------------------------------- ' Procedure : TestAge ' Author : Jack ' Date : 06-09-2012 ' Purpose : Routine to show the current age of a person given their DOB. 'This accounts for whether their birthday this year has occurred or not. '--------------------------------------------------------------------------------------- ' Last Modified: ' ' Inputs: N/A ' Dependency: N/A '-------------------------------------------------------------------------- ' Sub TestAge() Dim jage As Date On Error GoTo TestAge_Error jage = #9/29/1919# Debug.Print Age(jage) On Error GoTo 0 Exit Sub TestAge_Error: MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure TestAge of Module AWF_Related" End Sub
thank you,
i just dont understand this line:
(dteBase < intCurrent)
what its mean?
thank you,
miki
It is a means to subtract 1 from intEstAge if the person's Birthday has not yet passed, this year.
intEstAge = DateDiff("yyyy", dteDOB, dteBase)'<<<this gives the number of years using the difference in years only.
If the person's Birthday hasn't happened yet this year, you need to subtract 1 from intEstAge.
(dteBase < intCurrent) is a boolean 0 if False, -1 if True
Good luck.
aaa ok,It is a means to subtract 1 from intEstAge if the person's Birthday has not yet passed, this year.
intEstAge = DateDiff("yyyy", dteDOB, dteBase)'<<<this gives the number of years using the difference in years only.
If the person's Birthday hasn't happened yet this year, you need to subtract 1 from intEstAge.
(dteBase < intCurrent) is a boolean 0 if False, -1 if True
Good luck.
but how i can to calculate with month? like that 22.12?
i think to use in dateDiff("d",dob,now())/365.25
but its not accure because not all month is 30 day.
thank you,
miki
I'm not following your question.
WHAT exactly are you trying to do? Please see my post #2 where I first asked.
Datediff with days should give you an accurate figure -- you don't have to deal with the number of days in a month.
ok, i try to display the age in years and months.
i.e:if i born in 23/04/1992 my age is: 21.08 - 21 years and 8 mouths.
No it is not 21.08. It can be 21 years 8 months.
Try this
Good luckCode:Sub AgeMonths() Dim YearDiff As Integer Dim MnthDiff As Integer Dim Adjust As Integer Dim AgeWithMonths As String Dim Dob As Date 10 On Error GoTo AgeMonths_Error 20 Dob = #4/24/1992# 30 If Month(Dob) < Month(Date) Then 40 Adjust = 0 50 ElseIf Month(Dob) = Month(Date) And _ Day(Dob) <= Day(Date) Then 60 Adjust = -1 70 End If 80 YearDiff = DateDiff("yyyy", Dob, Date) + Adjust 90 MnthDiff = Month(Date) - Month(Dob) 100 AgeWithMonths = YearDiff & " " & MnthDiff 110 Debug.Print AgeWithMonths 120 On Error GoTo 0 130 Exit Sub AgeMonths_Error: 140 MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure AgeMonths of Module AWF_Related" End Sub