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

Conditionnal date calculating

The X
Registered: Mar 27 2011
Posts: 24

I'm using Acrobat X Pro and looking for a date calculation script based on text fields. I'm really new at this but I can't seem to find a way.
 
My fields:
day1 (date of an event in yyyymmdd format, always filled)
day2 (date of a possible event in yyyymmdd format, can be left blank)
day3 (Result of the calculation)
 
Now what I want is:
 
If day2 is left blank, then day3 = day1 + 7 days
If day2 is filled, then day3 = day2 + 6 months

My Product Information:
Acrobat Pro 10.1, Windows
The X
Registered: Mar 27 2011
Posts: 24
The way I see it would be to copy the same "onblur" script in both day1 and day2 as in:

day1 -> if day2 is blank
day3 = day1 + 7 days
else
day3 = day2 + 6 months

day2 -> if day2 is blank
day3 = day1 + 7 days
else
day3 = day2 + 6 months

Is there any easier method? What would the correct synthax be keeping the yyyymmdd format?
mmazal
Registered: Jul 20 2009
Posts: 27
you should be able to just place the code into the Calculation script for day 3

if (day2 == "")
{
event.value = day1 + 7 days
}
else
{
event.value = day2 + 6 months
}

the easiest way to do math with dates is to get them down to the millisecond level by converting them to date objects like so---

var d1 = util.scand("yyyymmdd", getField("day1").value)

//now d1.valueOf() is the d1 date in milliseconds

//add 7 days like this

var sevendays = 1000 * 60 * 60 * 24 * 7;

var x1 = d1.valueOf() + sevendays;

event.value = util.printd("yyyymmdd", x1);
try67
Expert
Registered: Oct 30 2008
Posts: 2398
@mmazal, your code will not work because x1 is not a Date object, just a number.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

mmazal
Registered: Jul 20 2009
Posts: 27
try67 is right

that last line should read

event.value = util.printd("yyyymmdd", new Date(x1));

another problem in my example seems to be that scand doesn't like the format yyyymmdd

it seems to be okay with yyyy-mm-dd

sorry for not being more helpful
mmazal
Registered: Jul 20 2009
Posts: 27
try67 is right

that last line should read

event.value = util.printd("yyyymmdd", new Date(x1));

another problem in my example seems to be that scand doesn't like the format yyyymmdd

it seems to be okay with yyyy-mm-dd

sorry for not being more helpful
try67
Expert
Registered: Oct 30 2008
Posts: 2398
"yyyymmdd" should work just fine, as long as you're using a valid Date object.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com