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

Help With day Calculation

nala5755
Registered: Jan 20 2011
Posts: 5
Answered

Need help with calc. a future date. Right now I have it where it calc. 25 days in the future. But need 25 working days in the future.
  
form1.Page1.Button1::click - (JavaScript, client)
 
var oNow = new Date();
// add 25 days and make new date object
oNow = new Date(oNow.getFullYear(), oNow.getMonth(), (oNow.getDate() + 25) )
// dispaly new date information
sMsg = "In 25 days it will be " + util.printd("mm/dd/yyyy", oNow);
sMsg += "\n" + "The day of the week will be " + util.printd("dddd", oNow);
app.alert(sMsg, 3, 0)

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Getting the number of Working days is a bit tricky because you have to detect the number of days before and after the weekends on the beginning and ending dates. Holidays are even trickier.

Do a search on "working days". There have already been some posts on the topic. In fact, I wrote a working days calculator at one point, I think it's linked in one of the posts.

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

nala5755
Registered: Jan 20 2011
Posts: 5
Accepted Answer
Thanks to Niall O'Donovan this problem has been solved:

var oNow = new Date();
var oDay = util.printd("dddd", oNow);

// add 25 working days and make new date object
if (oNow == "Saturday")
{
oNow = new Date(oNow.getFullYear(), oNow.getMonth(), (oNow.getDate() + 35 + 2));
}

else if (oNow == "Sunday")
{
oNow = new Date(oNow.getFullYear(), oNow.getMonth(), (oNow.getDate() + 35 + 1));
}

else
{
oNow = new Date(oNow.getFullYear(), oNow.getMonth(), (oNow.getDate() + 35));
}

// dispaly new date information
sMsg = "In 25 working days it will be " + util.printd("mm/dd/yyyy", oNow);
sMsg += "\n" + "The day of the week will be " + util.printd("dddd", oNow);
app.alert(sMsg, 3, 0);
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You still have the public holiday issue. Try starting on December 19, 2010. You will find there are at least 3 days lost to holidays.

George Kaiser