Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Days calculation excluding weekends
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Days calculation excluding weekends

 Post Reply Post Reply
Author
Pizush View Drop Down
New Member
New Member


Joined: 18 Mar 2018
Points: 1
Post Options Post Options   Quote Pizush Quote  Post ReplyReply Direct Link To This Post Topic: Days calculation excluding weekends
    Posted: 18 Mar 2018 at 3:36am
Hi



I made a pdf form in acrobat pro XI. In the file I need to calculate total days excluding weekends. I went through the community and come up with the below code. This code counts Saturday and Sunday as weekends.



// get the end date value

var Date1 = this.getField("From").value;



// get the start date value

var Date2 = this.getField("To").value;



var dDate2 = util.scand("dd/mm/yyyy H:MM:SS", Date2 + " 0:00:00");

var dDate1 =util.scand("dd/mm/yyyy H:MM:SS", Date1 + " 0:00:00");

event.value = calcBusinessDays(dDate1, dDate2);


function calcBusinessDays(dDate1, dDate2) { // input given as Date objects

    var iWeeks, iDateDiff, iAdjust = 0;

    if (dDate2 < dDate1) return -1; // error code if dates transposed

    var iWeekday1 = dDate1.getDay(); // day of week

    var iWeekday2 = dDate2.getDay();

    iWeekday1 = (iWeekday1 == 0) ? 7 : iWeekday1; // change Sunday from 0 to 7

    iWeekday2 = (iWeekday2 == 0) ? 7 : iWeekday2;

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

    iWeekday1 = (iWeekday1 > 5) ? 5 : iWeekday1; // only count weekdays

    iWeekday2 = (iWeekday2 > 5) ? 5 : iWeekday2;



    // calculate differnece in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)

    iWeeks = Math.floor((dDate2.getTime() - dDate1.getTime()) / 604800000)



    if (iWeekday1 <= iWeekday2) {

iDateDiff = (iWeeks * 5) + (iWeekday2 - iWeekday1)

    } else {

iDateDiff = ((iWeeks + 1) * 5) - (iWeekday1 - iWeekday2)

    }



    iDateDiff -= iAdjust // take into account both days on weekend



    return (iDateDiff + 1); // add 1 because dates are inclusive

}



I need to count Thursday and Friday as weekends. I have very little knowledge in javascript.

Any help would be greatly appreciated.


Regards
Back to Top
Sponsored Links


Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.016 seconds.