Skip to main content
Participant
June 15, 2022
Question

How do I convert this excel formula into Javascript for Custom Calculation Script (in fillable PDF)

  • June 15, 2022
  • 1 reply
  • 449 views

My Excel formula is =IF(A3>=DATE(2022,1,1),0.53,0.5)

 

This looks at a cell (e.g., A3) and determines whether or not the date in that cell is after Jan 1, 2022. If it is, then the value is .53 and if not, it is .50. The purpose of this formula is to auto-caluate mileage reimbursement rates.

 

I am not familar with Javascript, though I've been able to learn some things online (how to code if/thens). What I can't figure out is how to represent "greater than xx/xx/xx date" in JS.

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
June 15, 2022

You will need to convert the string to a Date object. This can be done using the scand method of the util object.

Then create another Date object representing this cut-off date, and compare the two by accessing their getTime methods, which returns a number.

Josh_CUAuthor
Participant
June 15, 2022

Unfortuantely I am not well enough versed to make sense of this, though I'll definitely look into your suggestions and see if I can piece some code toghether.