These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Date Calculation - Start Date Plus Number of Months

sjensen619
Registered: Mar 25 2010
Posts: 7

Hello,

I have a form setup for a loan calculation. I have a begin date and end date. The end date is calculated based off the begin date plus a number of months.

So basically:

Number of Payments: 12
First Payment Date: May 10, 2010
Final Payment Date: April 10, 2010

I can't get the "FinalPaymentDate" to calculate unless I use a date in "FirstPaymentDate" that is past the ninth of a month. For example, if I chose my start date as May 5, 2010 the calculation will fail. If I use May 10, 2010 everything works just fine.

I also had to make a little tweak concerning the year. Whenever the calculation would calculate the month of December it would jump to the next year. For example, I would have 09/01/2010, 10/01/2010, 11/01/2010, 12/01/2011, 01/01/2011.

I'm not sure how to post an example of my pdf but if I figure that out I'll upload it.

Also, I take no credit for writing the code below. I took an example gkaiseril posted a few years ago and made minor tweaks to suite my needs. He gets and deserves the credit for writing the code.

*************************************

if(HasValue(FirstPaymentDate)) then
// get date and parts of date
var fStart = Date2Num(FirstPaymentDate.formattedValue, "MMM DD, YYYY")
// get month as number
var fMonth = Num2Date(fStart, "MM")
// get date as number
var fDate = Num2Date(fStart, "DD")
// get 4 digit year
var fYear = Num2Date(fStart, "YYYY")
// advance months
fMonth = fMonth + (NumPayments - 1)
// adjust year for added months
fYear = fYear + Floor(fMonth / 12)
// adjust month between 1 and 12
// get remainder of months divided by 12 months per year
fMonth = Mod(fMonth, 12)
// make a remainder of 0 a value of 12
if (fMonth == 0)then
fMonth = fMonth + 12
endif
// fix the issue of December going to next year
if (fMonth == 12)then
fYear = fYear - 1
endif
// format month to 2 numbers
fMonth = Format("99", fMonth)
// create Iso Date string
var sNewDate = Concat(fYear, "-", fMonth, "-", fDate)
// display result
Num2Date(IsoDate2Num(sNewDate), "MMM DD, YYYY")
else
null
endif

--SID--
Registered: May 4 2010
Posts: 31
You can't calculate for date prior to 9th, because somewhere in the script, you have used DD, which means double digit date.

use only D, and it should make things better

~~ S I D ~~

sjensen619
Registered: Mar 25 2010
Posts: 7
Thank you for the reply. I wish the solution was that easy. The "DD" only changes the format.