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");
}
});
})();
|
Accepted answer
![]() Basically you're asking the same question as this one.
Abdelrahman Hassan selected this answer as the correct answer
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
![]()
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); } } }); })(); |