## Formcalc day calculation w/ minus or plus sign

26-01-2017

Forum,

I have a need to determine the quantity of days between two dates (todays date minus another), the code that I currently have (listed below) gives me the correct day count but additionally I need it to give me a + sign before the day count if the quantity of the days calculated are days that are preceding todays date and a - sign before the day count if the quantity of the days calculated are days that are after todays date.

Example;

Assumption; Todays date is 1/26/2017

If the start date of a project were 10/1/2016 than I need the calculation to be 10/1/2016 - 1/26/2017 =  + 118 days

or

If the start date of a project were 3/1/2017 than I need the calculation to be 1/26/2017 - 3/1/2017 =  - 35 days

The formcalc listed below gives me the correct day count (three different scenarios) but in the case of the first example listed above what it is currently giving me is - 118 days or for the second example, 35 days. I need the appropriate + or - symbol to precede the day count.

Current Formcalc code;

//Bill Bakers original code: this.rawValue = Date2Num(TableAvailDate, "YYYY-MM-DD") - Date2Num(TodayDate, "YYYY-MM-DD")

//FormCalc Calculate*

//Uses the closest start date (Current or New) to todays date to calculate A-minus

(BCRAction.rawValue == "Delete") then

= Date2Num(TableAvailDate, "YYYY-MM-DD") - Date2Num(TodayDate, "YYYY-MM-DD")

= Date2Num(TableNewStart, "YYYY-MM-DD") - Date2Num(TodayDate, "YYYY-MM-DD")

(BCRAction.rawValue == "Reschedule")

if (Date2Num(TableAvailDate, "YYYY-MM-DD") < Date2Num(TableNewStart, "YYYY-MM-DD"))then

= Date2Num(TableAvailDate, "YYYY-MM-DD") - Date2Num(TodayDate, "YYYY-MM-DD")

else

= Date2Num(TableNewStart, "YYYY-MM-DD") - Date2Num(TodayDate, "YYYY-MM-DD")

endif

R/

Matt