Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Quick question about setting a CF's parameters

Featured Replies

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

)

)

)

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

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

)

  • Author

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

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.

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

No such function.

Do you mean

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

  • 1 year later...
  • Author

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

:funnypost:

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.