How to subtract to dates and get the result in number of days

Avatar

Avatar
Level 1
Bassem_El_Sawy
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile

Avatar
Level 1
Bassem_El_Sawy
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile
Bassem_El_Sawy
Level 1

19-06-2019

I am creating a form for work and I already created two Date/Time Fields and I want a third field to automatically calculate the difference between the two dates in days. I then need to use this result in another equation. It goes as follows (for example):

Settlement Date (SD): 06/19/2019

Maturity Date (MD): 06/25/2019

Discount Rate (DR): 17.50%

Number of Days (ND): 6

First I need to calculate the number of dates and let it populate one of the fields in the form, so I need to let the form subtract whatever date is in SD from MD and give me the result in days.

Second, I need to use the result in days in the following equation

=(1/(((ND)/365)*(DR/100)+1))

or an equation that would directly go as =(1/(((MD-SD)/365)*(RD/100)+1))

Note:

I tried to use Excel formula to JavaScript converter and it didn't work.

I have no experience in Java and I am using LiveCycle Designer the comes with Adobe Professional 7

I use Windows 10 as an OS

I would really appreciate all the accurate help I can get. I am lost …. THANK YOU !!!!!!!!!!!

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

20-06-2019

Hi,

If all your users  have the latest version of Reader (that is DC) then you can use the following code to calculate the number of days in JavaScript

var sd = new Date(SD.rawValue);

var md = new Date(MD.rawValue);

Math.round((md.getTime() - sd.getTime())/(1000*60*60*24));

This assumes that your two date fields are called SD and MD, so you may have to change those.  I'm not sure were you need to put the code, if you are displaying the number of days in a field then put it in the calculate event of that field.  If it is only for the use in the expression then assign the result to another variable and use that, so;

var nd = Math.round((md.getTime() - sd.getTime())/(1000*60*60*24));

The "1000*60*60*24" is the number of milliseconds in a day, so if you want you could calculate that as its fixed.

If any of you users have older versions of Reader then replace the "new Date(SD.rawValue)" part with "

util.scand('yyyy-mm-dd', SD.rawValue) and the same on the next line.

Regards

Bruce