Jump to content

Quick question about setting a CF's parameters


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

Recommended Posts

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")

)

)

)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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" )

)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 1 year later...

This topic is 4518 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.