Click to See Complete Forum and Search --> : help birthdate computation


hexchad2009
June 2nd, 2009, 11:57 PM
Hi guys,

I have a problem obtaining the current age. Wherein the crystal computes the age by year as i use the DATEDIFF function. Is there any other way to compute the current age including the difference. Below is the code.


ClientDetailDOB = 5/27/1939
CurrentDate = 5/1/2009

Age as of currentdate : 69 years old there is a difference of 26 days to go before it turns 70. Now in crystal using DateDiff it returns 70 using the code below.

I need help. Thanks in advance.


Code:

varDOB = DateDiff("yyyy", ClientDetailDOB, CurrentDate)

ElseIf varDOB > 64 And varDOB <= 69 Then

If (varCDA < 11) Then
cInsurance = 17
ElseIf (varCDA >= 11) And (varCDA <= 15) Then
cInsurance = 7
Else
cInsurance = 0
End If

ElseIf varDOB = 70 Then

If (varCDA < 11) Then
cInsurance = 12
Else
cInsurance = 0
End If

jawadhashmi
June 8th, 2009, 12:32 AM
use the following formula to get the age at specific time in number of days, months and year.

By this you can find the exact age.


local datevar startdate := CDate("5/27/1939");
local datevar enddate := CDate("5/1/2009");

local numbervar date_1 := datepart("d", startdate);
local numbervar date_2 := datepart("d", enddate);

local numbervar month_1 := datepart("m", startdate);
local numbervar month_2 := datepart("m", enddate);

local numbervar year_1 := datepart("yyyy", startdate);
local numbervar year_2 := datepart("yyyy", enddate);

local numbervar date_diff := 0;
local numbervar month_diff := 0;
local numbervar year_diff := 0;

if(date_2 >= date_1) then
(
date_diff := date_2 - date_1
)
else
(
date_2 := date_2 + 30;
month_2 := month_2-1;
date_diff := date_2-date_1;
);

if(month_2 >= month_1) then
(
month_diff := month_2 - month_1
)
else
(
month_2 := month_2 + 12;
year_2 := year_2-1;
month_diff := month_2 - month_1;
);
year_diff := year_2 - year_1;

ToText(date_diff, 0) + "-" + ToText(month_diff, 0) + "-" + ToText(year_diff, 0);

ptaban50
June 16th, 2009, 06:37 AM
Hi Jawadhashmi,

Thanks for the answer, it was very useful.

Best regards

Peter