Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Date Calculation - Subtracting a variable number of days based on a numeric field

m_tirpak
Level 2
Level 2

Hi Everyone!

I have a complicated form situation. I'm trying to have it calculate when a person can start working on a report (Date C) based on the day a project ends (Date A) and the day the report is due (Date B). We have a set scale for when the Date C should be based on the difference between

The form has 2 dates that are entered by the user (Date A and Date B). I managed to calculate the difference between Date A and B that gives you a numeric value ( x days ). I need the form to calculate a third date (Date C) in that range based on the length of days between Date A and B.

The form currently does Date B - Date A = x days in javascript. Now I need the form to do the following:

Range CalculationCalculating Date C
if x days is ≥ 90 days    then Date C = Date B - 15 days
if x days is ≥ 30 and ≤ 89 days  then Date C = Date B - 10 days
if x days is 29 days ≤ 10 days    then Date C = Date B - 5 days
if x days is > 10 daysthen Message pop-up (We cannot accept an [x days value] less than 10 days without manager approval.)

From what I understand FormCalc is better with dates but I'm not as experienced with that language and I know I'm missing things.

1 Accepted Solution
m_tirpak
Correct answer by
Level 2
Level 2

Dove into FormCalc and answered my own question.

var pDate = Date2Num(Date A.formattedValue,"MM/DD/YYYY")

var mDate = Date2Num(Date B.formattedValue,"MM/DD/YYYY")

var kDays = mDate - pDate

if (kDays >= 90) then Num2Date(mDate - 15)

elseif ((kDays >= 30) & (kDays<= 89)) then Num2Date(mDate - 10)

else Num2Date(mDate - 5) endif

I'm managing the pop-up in a secondary way.

View solution in original post

1 Reply
m_tirpak
Correct answer by
Level 2
Level 2

Dove into FormCalc and answered my own question.

var pDate = Date2Num(Date A.formattedValue,"MM/DD/YYYY")

var mDate = Date2Num(Date B.formattedValue,"MM/DD/YYYY")

var kDays = mDate - pDate

if (kDays >= 90) then Num2Date(mDate - 15)

elseif ((kDays >= 30) & (kDays<= 89)) then Num2Date(mDate - 10)

else Num2Date(mDate - 5) endif

I'm managing the pop-up in a secondary way.

View solution in original post