Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Is there a way to calculate the number of business days between two dates - just exclude the weekends?

Is there a way to calculate the number of business days between two dates excluding the weekends using a calculated-value script.

I can get the number of days but I don't know how to exclude the weekends.

----------------------------------

dojo.provide("com.rm.ProjectDaysValueProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");

(function() {
    dojo.declare("com.rm.ProjectDaysValueProvider", null, {

        getValue: function(attribute, workItem, configuration) {
        
        // Get the start date and the end date and compute the difference in days.
        var startDate= dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.StartDate));
        var EndDate= dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.EndDaet));
//var startDate = workItem.getValue('StartDate');
//var endDate = workItem.getValue('EndDaet');
//var numOfProjectDays = " ";
if (startDate == null) {
Return " ";
}
else {
    if (EndDate == null) return " ";
                else return dojo.date.difference(startDate, EndDate, "day");
        }
    });
})();

0 votes


Accepted answer

Permanent link

Basically you're asking the same question as this one.
https://jazz.net/forum/questions/248138/calculating-the-number-of-working-days-between-two-given-dates

You can try the "interval" argument in the dojo.date.difference() function, and choose the value "weekday".
https://dojotoolkit.org/reference-guide/1.9/dojo/date.html

Abdelrahman Hassan selected this answer as the correct answer

0 votes

Comments
Thank you Donald. Your answer was really useful. I was able to calculate the days difference between two dates excluding weekends.

I'm adding the script in a different answer.


One other answer

Permanent link
Here is the script that worked for me after correcting some mistakes and following Donald's advise:

dojo.provide("com.example.DayDifference");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");

(function() {
    dojo.declare("com.example.DayDifference", null, {
    getValue: function(attributeId, workItem, configuration) {

try {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var startDate= dojo.date.stamp.fromISOString(workItem.getValue("StartDate"));
var endDate= dojo.date.stamp.fromISOString(workItem.getValue("EndDaet"));
var nullDate = null;

if ( startDate != nullDate && endDate!= nullDate) {
var dateDifference = dojo.date.difference(startDate, endDate, "weekday");
return dateDifference.toString();
}

else {
return nullDate;
}

}

catch(err) {
            var txt;
            txt="There was an error on this page.\n\n";
            txt+="Error description: " + err.message + "\n\n";
            txt+="Click OK to continue.\n\n";
            alert(txt);
        }

    }
    });
})();

<link href="moz-&lt;a href=" extension:="" 5f1d3e77-ea94-4dd3-8aef-5b56d386bc16="" skin="" s3gt_tooltip_mini.css""="">extension://5f1d3e77-ea94-4dd3-8aef-5b56d386bc16/skin/s3gt_tooltip_mini.css" rel="stylesheet" type="text/css"> <style media="print" type="text/css"> #s3gt_translate_tooltip_mini { display: none !important; } </style>

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 6,121

Question asked: May 01 '18, 11:16 a.m.

Question was seen: 3,225 times

Last updated: May 28 '18, 10:54 p.m.

Confirmation Cancel Confirm