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

Date calculates right except for November 2010

MACY8167
Registered: Sep 25 2010
Posts: 7
Answered

The below script is on a time sheet. The employee fills in the first date and the below script fills in the rest. This has worked for every time sheet except the current one. When 11/01/2010 is keyed in as the current date the value of 11/07/2010 is returned. The value should be 11/08/2010. Any ideas would be greatly appreciated
    
event.value = "";
 
// Get the string date from the current date field
var strDate = this.getField("DateCurrent").value;
 
// We already know the exact format since we put it there, makes it easy to scan
if(!/^\s*$/.test(strDate))
{
var oDate = util.scand("mm/dd/yy, ddd, hh:MM:ss ",strDate);
if(oDate)
{
// Calculate 5 years in milliseconds
var fiveDays = 7 * 24 * 60 * 60 * 1000;
// Create a new date object so we can format it
oDate = new Date(fiveDays + oDate.getTime());
event.value = util.printd("mm/dd/yyyy", oDate)

}
}
       

My Product Information:
Acrobat Pro Extended 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2399
First of all, the name of your variable and the comment are confusing.
You are actually adding 7 days to the date, not 5 days or 5 years.

I can't reproduce what is happening to you, but I think I have an idea why it is happening.
I had encountered a similar problem and then found out it was caused because of the winter time. It seems that JavaScript has a built-in mechanism which adds (or removes) an extra hour when there's a switch between day-time savings to winter time. As a result, such calculation can go wrong.

Try running this code:

console.clear();
var strDate = "11/01/2010";
if(!/^\s*$/.test(strDate)) {
var oDate = util.scand("mm/dd/yy, ddd, hh:MM:ss ",strDate);
if(oDate) {
var msPerDay = 24 * 60 * 60 * 1000;
console.println(oDate);
for(i=1; i<=7; i++) {
oDate1 = new Date((msPerDay*i) + oDate.getTime());
console.println(oDate1);
}
}
}

What's the output?

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

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
There's no need to work in milliseconds. Try this:


if(oDate) {

// Add five days
oDate.setDate(oDate.getDate() + 5);

event.value = util.printd("mm/dd/yyyy", oDate)

}
MACY8167
Registered: Sep 25 2010
Posts: 7
I was wondering about daylights savings time. I went with the second option above. It worked!! Thanks to both of you for taking the time to answer!