cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

dateDiffDays excluding weekends?

I'm new to nintex, i am currently trying to build form to do date difference, i have been able to do this by the dateDiffDays function in calculated value but i need to exclude weekends, does anyone know how i would do this?

0 Kudos
Reply
3 Replies
Not applicable

Re: dateDiffDays excluding weekends?

I need an answer for this too

0 Kudos
Reply
nidhincee
Nintex Newbie

Re: dateDiffDays excluding weekends?

// JavaScript source code

var HOLIDAYS = [];

function HolyDaysList() {
$().SPServices({
operation: "GetListItems",
async: false,
si: "http://devappsrv2/EN/HelpDesk",
listName: "Public holydays",
CAMLQuery: "<Query></Query>",
CAMLViewFields: "<ViewFields Properties='True'><FieldRef Name='Date' /> </ViewFields>",
CAMLQueryOptions: "<QueryOptions></QueryOptions>",
completefunc: function (xData, Status) {
if ($(xData.responseXML).SPFilterNode("z:row").length > 0) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
debugger;
var phday = new Date($(this).attr("ows_Date")).toISOString().slice(0, 10);
HOLIDAYS.push(phday);
});
}
}
});
}
NWF$(document).ready(function () {
debugger;
HolyDaysList();
var startDate = NWF$('.cssStartDate').find('input').val();
var dtSplit = startDate.split('/');
startDate = new Date(dtSplit[2], parseInt(dtSplit[1]) - 1, dtSplit[0]);
startDate.setDate(startDate.getDate() + 0);
var kpi = NWF$('.cssKPI').find('input').val();

var result = new Date();
var endDate = result.setDate(result.getDate() + parseInt(kpi) - parseInt(1));
var expEndDate = calcBusinessDays(startDate, endDate, kpi);
});

NWF$("#" + dtStartDate).change(function () {

var startDate = NWF$('.cssStartDate').find('input').val();
var dtSplit = startDate.split('/');
startDate = new Date(dtSplit[2], parseInt(dtSplit[1]) - 1, dtSplit[0]);
startDate.setDate(startDate.getDate() + 0);
var kpi = NWF$('.cssKPI').find('input').val();
var result = new Date();
result = startDate;
var endDate = result.setDate(result.getDate() + parseInt(kpi))
var startDateAct = NWF$('.cssStartDate').find('input').val();
var dtSplitAct = startDateAct.split('/');
startDateAct = new Date(dtSplitAct[2], parseInt(dtSplitAct[1]) - 1, dtSplitAct[0]);
startDateAct.setDate(startDateAct.getDate() + 0);
var expEndDate = calcBusinessDays(startDateAct, endDate, kpi);
});

function calcBusinessDays(d1, d2, kpi) {
if (NWF$.inArray(d1.toISOString().slice(0, 10), HOLIDAYS) > -1)
{
alert('You can not select public holiday as start date!!');
NWF$('.cssStartDate').find('input').val('');
NWF$('.cssExpEndDate').find('input').val('');
return;
}
var diff = kpi;
var work = diff;
var d = d1;
while (d <= d2) {
d = new Date(d);
if ((d.getDay() == 5) || (d.getDay() == 6)) {
work++;
new Date(d2).setDate(new Date(d2).getDate() + 1);
} else if (NWF$.inArray(d.toISOString().slice(0, 10), HOLIDAYS) > -1) {
work++;
new Date(d2).setDate(new Date(d2).getDate() + 1);
}
d.setDate(d.getDate() + 1);
}

kpi = work;
d1 = new Date(d1);
var expEndDate = d1.setDate(d1.getDate() + parseInt(kpi)-parseInt(1));
var exp = NWF$('.cssExpEndDate').find('input');
var a = new Date(expEndDate);
exp.datepicker('setDate', a);
}

0 Kudos
Reply
nidhincee
Nintex Newbie

Re: dateDiffDays excluding weekends?

You need something like this ..avoid public holiday part and do only weekends I have given friday and saturday as weekend.

for saturday and sunday give,

if ((d.getDay() == 0) || (d.getDay() == 6)) {
work++;
new Date(d2).setDate(new Date(d2).getDate() + 1);
}

0 Kudos
Reply