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

Calculating Difference in Months, Days 2

Status
Not open for further replies.

szeiss

Programmer
Apr 5, 2000
137
US
Using Crystal 8.5 with Oracle 8i backend. I have an end date using the CurrentDate function of CR and a start date called "PrevYear" which is a calculated field that finds the last day of the previous fiscal year (9/30/2003). I need to know how many months and days have elapsed since 9/30/2003 thru CurrentDate shown in this format 4.15.

Thanks,
Sherry
 
Take a look at the DateDiff function in the help. You can use it to get both the Months and the Days.

@Months_Difference
Code:
DateDiff("m",{table.PrevYear},{table.ThisYear})
Would give you the months difference

@Days_Difference
Code:
DateDiff("d",{table.PrevYear},{table.ThisYear})
Would give you the days difference

~Brian
 
Try this one:

datevar begin:= date(2003,09,30);
datevar end:= currentdate;

numbervar months:=datediff("m",begin,end);
numbervar begpart;
numbervar endpart;

datevar beginlast:= date(dateadd("m",1,begin)-1);
datevar endlast:= date(dateadd("m",1,end)-1);
begpart:=day(begin)/(beginlast - begin + 1);
endpart:=day(end)/(endlast - end );

months - begpart + endpart

Mike
 
Thanks, exactly what I was looking for.

Sherry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top