Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to convert number of days to Yr. Mths

Status
Not open for further replies.

Shusha

IS-IT--Management
Jun 27, 2001
50
CA
Hi there,

I am having some difficulty with the above mentioned problem. I have to obtain the no of days between a clients birthdate and the current date and then convert that information to how old the client is in Yrs. and mths.
Example:
Clients birthdate: Feb 8, 2000
Current date: Jan 8, 2002
what I would like to see in the report field is the client is 1 Yr.11mths
Is this possible.
Right now I am able to display the field as 1.9. It is giving me the fraction of the mth portion. What i actually want it to reflect is in yrs and mth. I am not too concerned about it being accurate to the very last date.

Any input in this query will be much appreciated.

Pls. send your replies to meisteru@hhsc.ca

Thanks for ur help

Usha
 
Try the DateDiff function. DateDiff (intervalType, startDateTime, endDateTime) with an intervalType of 'm' will calculate the number of months (in CR 8.x & above) between your startDateTime & your endDateTime.

HTH,
John Marrett
Crystal Reports & Crystal Enterprise Trainer
 
Hi,

I think that I have a solution:

Use this formula to calculate the years a person is:

WhileReadingRecords;
DateVar Birth:= {@leap}; // Replace this with your field for Date Of Birth
DateVar Ann := currentdate; // Replace this with CurrentDate to get their age as of the time of the report or
//or the date field of an event to get their age as of the time of that event.


if (Month(Ann) * 100) + Day (Ann) >=
(Month(Birth) *100) + Day (Birth)
then Year (Ann) - Year(Birth)
else Year (Ann) - Year(Birth) -1


Then use this formula to calculate the months the person is this year:

datediff("m", currentdate,date(year(currentdate-1),month({Employee.Birth Date}),day({Employee.Birth Date})) )

This formula will in how many months they have to go that year to be number of months this year that they have to go to be their new age. It is going to be on a full month basis but its close.

Then have this formula appear on your report:

if {@months} = 0 then
totext({@age},0)&" yrs "
else
if {@months} < 0 then
totext({@age},0)&&quot; yrs &quot;& totext((-{@months}),0)&&quot;months&quot;
else
totext({@age},0)&&quot; yrs &quot;& totext((12-{@months}),0)&&quot;months&quot;


I hope this works for you,

alley
 
You could also substitute this part for the months and it appears to do the same thing:

datediff(&quot;m&quot;, currentdate,date(year(currentdate),month({Employee.Birth Date}),day({Employee.Birth Date})) )


alley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top