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

Need Help Creating Date Script

Captain Vanhoy
Registered: Oct 23 2011
Posts: 5
Answered

Hello, first I hope I am posting this thread in the appropriate place.
 
We have a time sheet that has a field for a starting date. Then starting with the entered date there are 14 fields that represent each working day within the two week cycle. I need a script that will take the date entered (Field name is text) and add 1 additional day up to 14 days. All I have come up with is:
 
var d1 = new Date();
var num = d1.valueOf();
num += 1000 * 60 * 60 * 24 * 0;
var d2 = new Date(num);
event.value =util.printd("mm/dd", d2);
 
This grabs the current date and adds to it (Last digit on the num line) in this case it is the first day and adds nothing. I just need it to work off the entered date field (text). Please help! I have worked weeks on this and am not getting anywhere.

My Product Information:
Acrobat Pro 10.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
See if this helps: http://forums.adobe.com/thread/836872
Captain Vanhoy
Registered: Oct 23 2011
Posts: 5
I must be doing something wrong... Do I need any script for the field I enter the date into?

1. I have the field I am entering the date into: from_date

2. I have the first field which should take the date from #1 and add 14 days to it.

3. I have formatted both to Date fields and put them both in the mm/dd/yy format.

4. I tried both:

// Get date from field
var v = getField("from_date").value;
// Convert string to date
var d = util.scand('mm/dd/yyyy', v);
// Add 90 days
d.setDate(d.getDate() + 14);

&// Custom calculate script for "to" field
(function () {

// Get date from field
var v = getField("from_date").valueAsString;

// Convert string to date
var d = util.scand("mm/dd/yyyy", v);

// Add 14 days
d.setDate(d.getDate() + 14);

// Populate this field with the result
if (v) {
event.value = util.printd("mm/dd/yyyy", d);
} else {
event.value = "";
}

})();


Both are showing no results at all. Also no script errors. ? Any ideas, also thanks for the quick response. Your help is very much appreciated!




George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Accepted Answer
You should not use that first script fragment anywhere. It was intended to be instructional, not a complete script.

The second is intended to be a custom calculation script. It works fine for me, but you would need to change the first "mm/dd/yyyy" to "mm/dd/yy". Is that how you used it and did you remove the first script from wherever you placed it?
Captain Vanhoy
Registered: Oct 23 2011
Posts: 5
Thank-you so much George for the help. This script works great. I couldn't thank-you enough.