Avatar of Kevin
Kevin
Flag for United States of America asked on

How do I subtract two dates in LiveCycle?

Good Afternoon,

I am using LiveCycle Designer ES2.

Management has provided me with a formula they would like to use on the form for the “Interest Amount” field.

The Formula is:  InterestAmt = PrincipalAmt * TotalInterestRate / 360 * (MaturityDate - SettlementDate)

I am only familiar with basic calculations, so this task of making the formula work, especially with subtracting the date fields is very difficult. I know from reading several posts on google that Adobe Acrobat deals with milliseconds cause of the epoch date. But I am still clueless on where to begin.

I think I can complete the above formula once I can know how to subtract one date from the other.

Can someone please provide me with some code to complete the date subtraction for my LiveCycle form?

Do advise if additional information is required.

Kind Regards,
N
JavaScript

Avatar of undefined
Last Comment
Dan Craciun

8/22/2022 - Mon
Dan Craciun

days = get-days-from-date-difference('2014-03-01','2014-02-01')

This should return 28, or the number of days between the two dates.

See here: http://help.adobe.com/en_US/livecycle/9.0/workbenchHelp/help.htm?content=000788.html

HTH,
Dan
Dan Craciun

Or, in Javascript:

// Get difference between dates in milliseconds
   var milliseconds = MaturityDate.getTime() - SettlementDate.getTime();
 
   // Define number of milliseconds in one day
   var nMilliSecondsPerDay = 24 * 60 * 60 * 1000;
 
   // Get difference in days
   var days = Math.floor(milliseconds / nMilliSecondsPerDay);

Open in new window

Kevin

ASKER
Morning Dan,

Thank you for both of your answers.

I apologize for not putting more detail in my question. The date (Maturity and Settlement) is actually 2 fields. So your first answer won’t help me, since the user will be selecting their own dates. But it’s OK as I was expecting a JavaScript answer like your second answer.

Only problem is that I am not able to get it to work with the formula. I have stripped the formula to just concentrate on getting the value for the dates. My screenshot shows what I have, essentially the value should appear in the Numeric1 field, but when I select the dates nothing appears in this field and I am not sure why.

ss
Do you have any ideas?

I have also attached this PDF that I am testing in LiveCycle.

Kindly advise.

Regards,
N
DateSubtractTEST.pdf
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Dan Craciun

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Kevin

ASKER
Ah OK I see.

Thank you so much Dan.
Dan Craciun

You're welcome.
Glad I could help!