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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turning days into Years, Months, Days

Status
Not open for further replies.

WPCMS

Technical User
Jun 28, 2007
29
US
I have a report that counts the days the account is in process. Some accounts have been in process for a few years. I would like my formula to break it down by years, then months, then days. How can I go about doing that?
Thanks,
WPCMS
Program:Crystal Reports IX
Level:Beginner
 
The following assumes you have inserted a group on {table.acct} and that you have one date field you are comparing across years. Go to the field explorer->formula->new and enter:

datetimevar min := minimum({table.date},{table.acct);
datetimevar max := maximum({table.date}, {table.acct});
numbervar yrs := datediff("yyyy",min,max);
numbervar mos;
if month(max) >= month(min) then
mos := datediff("m",min,max)-(yrs*12) else
if month(max) < month(min) then (
yrs := yrs-1;
mos := datediff("m",min,max)-(yrs*12)
);
numbervar days :=
if day(max)>= day(min) then
days := day(max) - day(min) else
if day(max) < day(min) then (
mos := mos-1;
days := day(max)+(day(max-day(max))-day(min))
);
totext(yrs,0,"")+" Yrs "+totext(mos,0,"")+" Mos "+totext(days,0,"")+ " Days"

Place the formula in the group section based on {table.acct}.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top