Kevin

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

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

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);
```

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.

Do you have any ideas?

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

Kindly advise.

Regards,

N

DateSubtractTEST.pdf

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.

Do you have any ideas?

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

Kindly advise.

Regards,

N

DateSubtractTEST.pdf

ASKER CERTIFIED SOLUTION

membership

This solution is only available to members.

To access this solution, you must be a member of Experts Exchange.

ASKER

Ah OK I see.

Thank you so much Dan.

Thank you so much Dan.

You're welcome.

Glad I could help!

Glad I could help!

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