Dynamically Add Days to a Selected Date

I am creating a mobile app to calculate PTO for my company and am having some problems with the date calculations.

I am using a transformer to calculate the number of days needed to earn enough PTO.

What I am wanting is if that transformer {{Days}} is <= 0 then pull the date that was input in the {{Date}} component. If not, then I want to add the {{Days}} number to the inputted {{Date}}.

EX: 5 days needed so if they had put in 06/10/2023, it would return 06/15/2023.

I have not been able to figure out something that accomplishes this. Most attempts either concat the values or return "NaN".

As a frame of reference, I am just starting off with learning SQL, and use these forms and Google to figure out JS and the rest. (Also, I have been testing my ideas in {{DateRecovered}} and {{Query7}}, I have also attempted to use a SmartQuery but it wasn't much help with this)

PTO Calculator (1).json (35.7 KB)

Check out this link

1 Like

That helped a lot. Thank you very much, Scott.

The final product ended up looking like this.

var day = Days.value
var date = Date.value

let response;

response = day <= 0 ? date :
  moment(date).add(day,'d').local().format('LL')

return response

I don't think the local() is needed but it works so I'm not going to mess with it.

2 Likes