We help IT Professionals succeed at work.

How do I subtract two dates in LiveCycle?

Kevin
Kevin asked
on
1,703 Views
Last Modified: 2014-05-07
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
Comment
Watch Question

Dan CraciunIT Consultant
CERTIFIED EXPERT

Commented:
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 CraciunIT Consultant
CERTIFIED EXPERT

Commented:
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

KevinInformation Technology

Author

Commented:
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
IT Consultant
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
KevinInformation Technology

Author

Commented:
Ah OK I see.

Thank you so much Dan.
Dan CraciunIT Consultant
CERTIFIED EXPERT

Commented:
You're welcome.
Glad I could help!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.