Link to home
Start Free TrialLog in
Avatar of Kevin
KevinFlag 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,
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

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:

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

Avatar of Kevin


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.

User generated image
Do you have any ideas?

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

Kindly advise.

Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kevin


Ah OK I see.

Thank you so much Dan.
You're welcome.
Glad I could help!