Skip Ribbon Commands
Skip to main content
ITLAQ Technologies

Skip Navigation LinksDiscussions List : Calculating Working Days between two dates
Use the Discussion list to hold forum-style conversations, including question and answer, on topics relevant to your team, project, or community.

Edited: 11/10/2017 11:29 PM
Picture: Jim Hidson
Jim Hidson
Calculating Working Days between two dates

In order to calculate the number of working days between two dates in SPARK you can use the following script which substitutes the weekend days from the total number of days between these two dates.

Controls: Date1, Date2 , TextBox1

Script:

function getWeekendDays(d1,d2){
    var start = new Date(d1),
    finish = new Date(d2),
    dayMilliseconds = 1000*60*60*24;
    var weekendDays = 0;
    while (start <= finish) {
      var day = start.getDay()
      if (day == 0 || day == 6) {
         weekendDays++;
        }
      start = new Date(+start + dayMilliseconds);
    }

    return weekendDays
}

var weekendday= getWeekendDays(getValue(Date1),getValue(Date2))

var differnceDay=calculateDays(Date1,Date2)+1

var numberOfFinalDays=differnceDay-weekendday
 
setValue(TextBox1,numberOfFinalDays)

 

Picture: Jim Hidson
  • Jim Hidson
/my/User%2520Photos/Profile%2520Pictures/jim_MThumb.jpg?t=63627189186" alt="Picture: Jim Hidson" />
Jim Hidson

In order to calculate the number of working days between two dates in SPARK you can use the following script which substitutes the weekend days from the total number of days between these two dates.

Controls: Date1, Date2 , TextBox1

Script:

function getWeekendDays(d1,d2){
    var start = new Date(d1),
    finish = new Date(d2),
    dayMilliseconds = 1000*60*60*24;
    var weekendDays = 0;
    while (start <= finish) {
      var day = start.getDay()
      if (day == 0 || day == 6) {
         weekendDays++;
        }
      start = new Date(+start + dayMilliseconds);
    }

    return weekendDays
}

var weekendday= getWeekendDays(getValue(Date1),getValue(Date2))

var differnceDay=calculateDays(Date1,Date2)+1

var numberOfFinalDays=differnceDay-weekendday
 
setValue(TextBox1,numberOfFinalDays)

 

011/10/2017 11:21 PM11/10/2017 11:29 PMNoCodes & Scripts
0
2/25/2017 5:38 PM
There are no items to show in this view of the "Discussions List" discussion board.