Expand my Community achievements bar.

SOLVED

Help With day Calculation

Avatar

Level 2

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)

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I haven't tried this but it should be close:

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

The 35 is seven days for for each of the 5-day working weeks. The +2 and +1 push a weekend into the next working day.

Hope that works,

Niall

Assure Dynamics

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Hi,

I haven't tried this but it should be close:

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

The 35 is seven days for for each of the 5-day working weeks. The +2 and +1 push a weekend into the next working day.

Hope that works,

Niall

Assure Dynamics