Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4732 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Howdy, howdy...

I nabbed the following CF (Tony Tanevski, Hi-Voltage, author) from Brian Dunning's site so I can have a calc display the difference between two dates in the following format: "2 years, 6 months"; I have a quick question since I'm a little hazy about CFs:

What are the parameters (xMonths, xYears, Months?) I'd use and how would I code the calc for say, field names Date1 and Date2?

TIA for your help!

-----------------------------------------------

Case(not IsEmpty(Months) and Months >=0 and months <> "?";

Let(

[

xYears = Int(Months / 12);

xMonths = Case(Months - (12 * xYears) > 0; Months - (12 * xYears))

];

Case(

xYears = 1;

"1" & Case(xMonths <> 0; " Yr"; " Year");

xYears > 1;

xYears & Case(xMonths <> 0; " Yrs"; "Years")

)

& Case(xYears <> 0 and xMonths <> ""; " , ") &

Case(

xMonths = 1;

"1" & Case(xYears <> 0; " Mth"; " Month");

xMonths > 1;

xMonths & Case(xYears <> 0; " Mths"; " Months")

)

)

)

Posted (edited)

Not sure what you mean by "code the calc."

Custom functions have NO field names inside their definition and you would make no changes to the custom function definition.

It would be helpful to mention the link to the original CF.

Edited by Guest
Posted

The custom function you mention has one parameter: Months and it converts the given number of months to years-and-months. I don't think you need a custom function for this, since the task is just as trivial as converting inches to feet-and-inches.

To express the difference between two dates in years-and-months, try =


Let ( [

em = 12 * Year ( EndDate ) + Month ( EndDate ) - 12 * Year ( StartDate ) - Month ( StartDate )  - ( Day ( StartDate ) > Day ( EndDate ) ) ;

y = Div ( em ; 12 ) ;

m = Mod ( em; 12 ) 

];

Choose ( Min ( y ; 2 ) ; "" ; "1 year " ; y & " years " )

&

Choose ( Min ( m ; 2 ) ; "" ; "1 month" ; m & " months" )

)

Posted (edited)

As usual, your calc worked great, Comment. Many thanks!

Bruce: the CF is from here:

http://www.briandunning.com/cf/437

What I meant by "coding the calc" was the syntax used in the calculation, e.g.:P

tablename::Month(Date1);tablename:Month(Date2)

Edited by Guest
Posted

Custom functions are used in the same way as other functions. If you have a custom function in the form of SomeFunction ( parameterA ; parameterB ), you would call it in a calculation formula as:

SomeFunction ( YourFieldA ; YourFieldB )

or similar.

Posted

"tablename::Month(Date1);tablename:Month(Date2) "

No such function.

Do you mean

month( tablename::Date1); month(tablename::Date2)

  • 1 year later...
Posted

You're right. Sorry for taking so long--I was waiting for the plumber to show up.

This topic is 4732 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.