September 3, 201015 yr 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") ) ) )
September 3, 201015 yr 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 September 3, 201015 yr by Guest
September 3, 201015 yr 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" ) )
September 3, 201015 yr 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. tablename::Month(Date1);tablename:Month(Date2) Edited September 3, 201015 yr by Guest
September 3, 201015 yr 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.
September 3, 201015 yr "tablename::Month(Date1);tablename:Month(Date2) " No such function. Do you mean month( tablename::Date1); month(tablename::Date2)
December 10, 201114 yr Author You're right. Sorry for taking so long--I was waiting for the plumber to show up.
Create an account or sign in to comment