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

How to calculate months and years

Status
Not open for further replies.

yatesk

Technical User
Dec 1, 2006
14
US
I am trying to create a report that calculates the age of a case....this is what I have now
DateDiff ("d",{CASE_PHYSICAL_TABLE.casefiled date},CurrentDate ), however, I want the report to say after the 30th or 31st day display as "1 month and (x) days"...then after the 365th day, "1 year and (x) days and (x)months.

Help me out. Thanks.
 
So if a date started on Feb 1st, and ended on March 1st, that would be 29 days, which would be displayed how in your requirements, 29 days?

It's clearly greater than a month though.

Anyway, here's a formula, replace the dates with your dates:

whileprintingrecords;
stringvar Output:="";
numbervar MyDays:=DateDiff ("d",currentdate,CurrentDate+430);
numbervar MyMonths:=DateDiff ("d",currentdate,CurrentDate+430)/30;
if MyDays < 30 then
Output:= totext(MyDays,0,"") & " days."
else
if MyDays < 365 then
Output:= totext(int(MyMonths),0,"") & " months and " & totext(remainder(MyDays,30),0,"") & " days."
else
if MyDays >= 365 then
Output:= totext(int(MyDays/365),0,"") & " years and " & totext(int(remainder(MyDays,365)/30),0,"") & " months and " & totext(remainder(remainder(MyDays,365),30),0,"") & " days."

-k
 
This is great SynapseVampire but what does the number 430 represent. that is the only part of the funtion I don't get.
Thanks,
Rob
 
Read the post, replace the dates with your dates.

I used those for testing...

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top