• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Calculate working days excluding sat and sun - updating script

Explorer ,
Jun 08, 2023 Jun 08, 2023

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 

TOPICS
Acrobat SDK and JavaScript

Views

474

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 08, 2023 Jun 08, 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

Votes

Translate

Translate
Community Expert ,
Jun 08, 2023 Jun 08, 2023

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 08, 2023 Jun 08, 2023

Copy link to clipboard

Copied

t.PNGsomething is not right here with only on calculation of friday, not sure about it

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 08, 2023 Jun 08, 2023

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 🥺

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 08, 2023 Jun 08, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines