Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
something is not right here with only on calculation of friday, not sure about it
Copy link to clipboard
Copied
@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 🥺
Copy link to clipboard
Copied
I'm getting a result of 6 for those dates. I bet the issue is with the switch to daylight savings (which fell on 03/26 this year), since you're calculating the difference using milliseconds. I would recommend using a counter, counting up the days from the first day to the last one (skipping weekends, of course), to avoid such issues. Also, you need to include a condition that checks if the fields are empty, as that's currently producing incorrect results (and errors).