Date Prob..........?

  • Thread starter Thread starter KRISH
  • Start date Start date
K

KRISH

Hi!
Everybody.

I am getting incorrect result while calculting the
difference of two dates. Actually I want to calculate age
on say 1st Nov, 2003 of a person whose date of birth is
11th Feb 1967.
I used
Format((CDate(DLookup("[Age
on]", "Calculations", "[Programme]='" & Me.Programme
& "'")) - CDate(Me.DateOfBirth)), "mm-dd-yy")

gives 09-19-36 (19days 9months 36 years) actually
result is 20days 8months 36 years. It is ignoring one day
in the above given Nov month.

Any help is appreciable.

Krish
 
Your formula is flawed...you can't do straight subtraction to determine
age...use this function instead:

Function GetAge(BirthDate As Date, Optional AsOfDate As Date = 0) As Integer

On Error Resume Next

'See if an arg was passed for AsOf date, if not, use today's date
If AsOfDate = 0 Then
AsOfDate = Date
End If

'Get the number of years difference between the birthdate and AsOf
GetAge = DateDiff("yyyy", BirthDate, AsOfDate)

'If the birthdate is not passed AsOf, we need to subtract a year
GetAge = GetAge + (AsOfDate < DateSerial(Year(AsOfDate),
Month(BirthDate), Day(BirthDate)))

End Function
 
Thanks for your mail. But your code is giving only years
but not the month and days.

Krish
-----Original Message-----
Your formula is flawed...you can't do straight subtraction to determine
age...use this function instead:

Function GetAge(BirthDate As Date, Optional AsOfDate As Date = 0) As Integer

On Error Resume Next

'See if an arg was passed for AsOf date, if not, use today's date
If AsOfDate = 0 Then
AsOfDate = Date
End If

'Get the number of years difference between the birthdate and AsOf
GetAge = DateDiff("yyyy", BirthDate, AsOfDate)

'If the birthdate is not passed AsOf, we need to subtract a year
GetAge = GetAge + (AsOfDate < DateSerial(Year (AsOfDate),
Month(BirthDate), Day(BirthDate)))

End Function

--
Paul Overway
Logico Solutions, LLC
www.logico-solutions.com


KRISH said:
Hi!
Everybody.

I am getting incorrect result while calculting the
difference of two dates. Actually I want to calculate age
on say 1st Nov, 2003 of a person whose date of birth is
11th Feb 1967.
I used
Format((CDate(DLookup("[Age
on]", "Calculations", "[Programme]='" & Me.Programme
& "'")) - CDate(Me.DateOfBirth)), "mm-dd-yy")

gives 09-19-36 (19days 9months 36 years) actually
result is 20days 8months 36 years. It is ignoring one day
in the above given Nov month.

Any help is appreciable.

Krish


.
 
You said you wanted to know age. I gave you the calculation for age.

--
Paul Overway
Logico Solutions, LLC
www.logico-solutions.com


Krish said:
Thanks for your mail. But your code is giving only years
but not the month and days.

Krish
-----Original Message-----
Your formula is flawed...you can't do straight subtraction to determine
age...use this function instead:

Function GetAge(BirthDate As Date, Optional AsOfDate As Date = 0) As Integer

On Error Resume Next

'See if an arg was passed for AsOf date, if not, use today's date
If AsOfDate = 0 Then
AsOfDate = Date
End If

'Get the number of years difference between the birthdate and AsOf
GetAge = DateDiff("yyyy", BirthDate, AsOfDate)

'If the birthdate is not passed AsOf, we need to subtract a year
GetAge = GetAge + (AsOfDate < DateSerial(Year (AsOfDate),
Month(BirthDate), Day(BirthDate)))

End Function

--
Paul Overway
Logico Solutions, LLC
www.logico-solutions.com


KRISH said:
Hi!
Everybody.

I am getting incorrect result while calculting the
difference of two dates. Actually I want to calculate age
on say 1st Nov, 2003 of a person whose date of birth is
11th Feb 1967.
I used
Format((CDate(DLookup("[Age
on]", "Calculations", "[Programme]='" & Me.Programme
& "'")) - CDate(Me.DateOfBirth)), "mm-dd-yy")

gives 09-19-36 (19days 9months 36 years) actually
result is 20days 8months 36 years. It is ignoring one day
in the above given Nov month.

Any help is appreciable.

Krish


.
 
Back
Top