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)
}
}
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