Skip to main content
Known Participant
June 8, 2023
Answered

Calculate working days excluding sat and sun - updating script

  • June 8, 2023
  • 1 reply
  • 1024 views

Hey guys!

 

I have a query. I have 2 dates and a text box calclating working days excluding sat and sun. Everything is working well unless i enter start date as sat or sun, the calculation then starts adding that sat or sun also. 

Example: (format: mm/dd/yyyy)

 

Begin date: 04/09/2023(sunday) - End Date: 04/17/2023(monday) so W.Days should be 6 excluding the start date sunday but unfortunately I'm getting 7 days. Same problem is occuring when i enter start and end date as sat and sun then the entire calculation is messing up.

 

I'm attaching the file and I'm not good with js, please if anyone can help me with the script 

This topic has been closed for replies.
Correct answer try67

Change this line:

 

if ((iWeekday1 > 5) && (iWeekday2 > 5)) iAdjust = 1; // adjustment if both days on weekend

 

To:

 

if (iWeekday1 > 5) iAdjust++; // adjustment if either day on weekend
if (iWeekday2 > 5) iAdjust++; // adjustment if either day on weekend

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 8, 2023

Change this line:

 

if ((iWeekday1 > 5) && (iWeekday2 > 5)) iAdjust = 1; // adjustment if both days on weekend

 

To:

 

if (iWeekday1 > 5) iAdjust++; // adjustment if either day on weekend
if (iWeekday2 > 5) iAdjust++; // adjustment if either day on weekend

Known Participant
June 8, 2023

something is not right here with only on calculation of friday, not sure about it

Known Participant
June 8, 2023

@try67 can you help me please? I'm almost done and you solution did worked but now its just giving wrong calculation when I'm adding a date of Fridays 🥺