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

Date Calculation with formcalc

realname
Registered: Aug 15 2008
Posts: 93

I have a form where I am trying to put in a calculation to return the date a person will turn age 65.

The following code works, however, there are times when the returned date is off by a day.

Num2Date(Date2Num(DOB.formattedValue, "MMM D, YYYY") + (365.25*65))

Is there a better way I can calculate this or alternatively, can I have the returned date display only the month and day? I tried to change the field display to MMM, YYYY however, it still gives me a day of the month.

Thanks!

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The Num2Date function is what formats the date. So this is where you need to add a formatting parameter, like this.

Num2Date(Date2Num(DOB.formattedValue, "MMM D, YYYY") + (365.25*65), "MMM, YYYY" )
And yes, there is a better way to do the calculation. You're a bit off because of rounding in the leap year fudge. A better method would be to simply split out the components of the DOB and add 65 to the year. Then rebuild the date strintg.

Something like this

var nDateNum = Date2Num(DOB.formattedValue, "MMM D, YYYY") ;var cYr = (Num2Date(nDateNum ,"YYYY") + 65)var cMo = Num2Date(nDateNum,"MMM")var cDay = Num2Date(nDateNum,"D")Concat(cMo," ", cDay, ", ", cYr)

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

realname
Registered: Aug 15 2008
Posts: 93
Thank you very much! That was exactly what I was trying to do.
disssg
Registered: Dec 10 2008
Posts: 12
I am planining to use my form that once user enters date of birth to one field next field (age) supposed to calculate and display age (year only). Is this possible? So in this case I am trying to display date of birth as well as age in two seperate fields.
please help.. By the way I am bit new to LiveCycle
Thanks
Disssg
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There are actually quite a few ways to do this. Some of the simpler methods can get tripped up by leap years, but for the most part they are close enough. Here's a post that explains one.

http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=587

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

susuns
Registered: Jul 7 2010
Posts: 11
I need a sample of a calculation to determine the number of days between two dates. I have tried to understand from the posts that you have recommended, but I can't seem to get it - HELP!
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
@ susuns

Hi,

look at this thread.
[url]http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=21544[/url]

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Depending upon what days you are counting, you may need to include the start day as a counted day, like in computing days present at a location or for age calculations. For this situation, you will need to add 1 to the result.

George Kaiser

brettmatsuura
Registered: Jul 31 2010
Posts: 1
I have been trying to figure out the script to determine the number of days that have passed since a date in Livecycle Designer.

For example, if I input a date in one field, I would like the field next to it to determine how many days have passed since that date.

Can anyone help me out with any copy and paste code?

Brett

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You could create a field with todays date and then use that date for the ending date and the imputed date for the starting date. With those 2 fields you should be able to use the 'Num2Date' function to convert the formatted string values for the date to the number of days since the epoch date and the difference of those 2 dates plus 1 will be the number of days that have past.

With out knowing the exact name of the fields and the exact format for the date fields, it is very hard to provide a cut and paste code.

George Kaiser