It's all about the answers!

Ask a question

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

Abdelrahman Hassan (199) | asked May 01 '18, 11:16 a.m.

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.



(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=;
        var EndDate=;
//var startDate = workItem.getValue('StartDate');
//var endDate = workItem.getValue('EndDaet');
//var numOfProjectDays = " ";
if (startDate == null) {
Return " ";
else {
    if (EndDate == null) return " ";
                else return, EndDate, "day");

Accepted answer

permanent link
Donald Nong (14.4k313) | answered May 01 '18, 9:06 p.m.

Basically you're asking the same question as this one.

You can try the "interval" argument in the function, and choose the value "weekday".

Abdelrahman Hassan selected this answer as the correct answer

Abdelrahman Hassan commented May 28 '18, 10:50 p.m. | edited May 28 '18, 10:52 p.m.
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
Abdelrahman Hassan (199) | answered May 28 '18, 10:52 p.m.
edited May 28 '18, 10:54 p.m.
Here is the script that worked for me after correcting some mistakes and following Donald's advise:


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

try {
var WorkItemAttributes =;
var startDate="StartDate"));
var endDate="EndDaet"));
var nullDate = null;

if ( startDate != nullDate && endDate!= nullDate) {
var dateDifference =, 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";


<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>

Your answer

Register or to post your answer.