 Level 1

0% to Level 2

Tip /

to gain points, level up, and earn exciting badges like the new
Mission!

View all

## Calculating a new date: adding days then subtracting a variable. AL0001
Level 1

Likes

0 likes

Total Posts

7 posts

0 solutions
View profile

AL0001
Level 1

Likes

0 likes

Total Posts

7 posts

0 solutions
View profile
AL0001 Level 1

21-07-2017

Hello:  I'm a newbie to javascript and have a little experience with LiveCycle.

I'm working on a form which will allow an applicant to calculate an approximate graduation date if they're getting an Associates Degree.  They enter their start date (Start_Date) and total credits earned to date in another field.  The Credits field returns a variable which reduces the graduation date.  So, I need to take the Start_Date, add 1068 days (which is 35 months converted roughly to days), then subtract the variable calculated from the Credits field and display an estimated graduation date.  I have tried many different ways of doing this based on examples I've found, and though LiveCycle says the syntax is OK, nothing will display in the field.  I hope this makes sense.  I'm taking a relatively simple Excel "calculator" and adding it to this form, but I just don't know enough about Javascript to get it to work.

I hope this makes sense.  I need:

1. User enters Start Date & Credits Earned

2. Associates Degree field would calculate Start Date + 1068 days (~35 months from the date entered)

3. If any credits have been earned to date, a variable (converting credits earned to a number of days, which I already have calculating correctly in a hidden field) would be subtracted

Start Date + 1068 days - Variable = Graduation Date

Any help would be appreciated.

#### Accepted Solutions (0) MVP

Likes

397 likes

Total Posts

2,687 posts

492 solutions
View profile

MVP

Likes

397 likes

Total Posts

2,687 posts

492 solutions
View profile MVP
`if (not \$.isNull) thenvar cPattern = "DD.MM.YYYY" ;How the entered date is formattedvar cStartDate = \$.formattedValue ;The entered anf formatted datevar iStartDate = Date2Num(cStartDate, cPattern) ;The date converted into an integervar iNumMonths = 35 ;Months to countvar iNumSubtractDays = 7 ;Value to be subtracted later.var iNumCount = 0 ;Month counter;A while loop that executed as long the desired number of months have been countedwhile (iNumCount lt iNumMonths) do;If current month is different to previous month …if (Num2Date(iStartDate, "M") ne Num2Date(iStartDate - 1, "M")) then;…add 1 month to the counteriNumCount = Sum(iNumCount + 1)endif;Add 1 day to the counter for the next iteration of the while loopiStartDate = Sum(iStartDate, 1)endwhile;Show result in textfield etc.Textfield = Num2Date(Sum(iStartDate, -1, iNumSubtractDays), cPattern)endif`