Excluding days from day count

I have a table that shows orders that are shipping out for any particular day. I was asked to add a column that would display the number of days between the product build date and ship date. This was easy enough using the code in the value box of the added column:

{{ moment(currentSourceRow.ship_date).diff(moment(currentSourceRow.build_date), 'days') + ' days' }}

Unfortunately, I forgot that # of days needs to exclude Fridays, Saturdays and Sundays. Is there something different I can use in the value box to achieve this or is it more involved then that?

Thanks in advance.

It's just a tiny bit more involved.
You need to loop through your days, check it's not one of your excluded days and add it to the count.

I understand that, I just don't know how to include that in the code I am already using in the value box, or if I even can.

Hi @tomm,

You can use the following script to calculate the difference between the ship date and build date while excluding Friday, Saturday, and Sunday:

{{ (() => { let s=moment("2025-08-22"), e=moment("2025-09-30"), c=0; for(let m=moment(s); m.isSameOrBefore(e,'day'); m.add(1,'days')){ let d=m.day(); if(d!==0 && d!==5 && d!==6) c++; } return c+' days' })() }}

For example, if the start date is 22-08-2025 and the end date is 30-09-2025, the total difference (excluding Fridays, Saturdays, and Sundays) will be 22 days.

Let me know if you need any further help!

1 Like

Thanks for the response. I attempted to use this code with a slight variation. I needed it to use the correct start date and end date for each record, so this is what I used:

{{ (() => { let s=moment(currentSourceRow.ship_date), e=moment(currentSourceRow.build_date), c=0; for(let m=moment(s); m.isSameOrBefore(e,'day'); m.add(1,'days')){ let d=m.day(); if(d!==0 && d!==5 && d!==6) c++; } return c+' days' })() }}

I ended up getting a zero for every record.

1 Like

Could you share a mock JSON response similar to your data output? That way I can take a closer look and help identify what might be causing the issue.

1 Like

Please forgive my ignorance, but I’m not sure what you mean by a mock JSON response.

1 Like

A mock JSON response just means an example of how your currentSourceRow data looks. If you’re comfortable, you can share the actual currentSourceRow object so we can see the structure.

If it contains sensitive or personal data, no worries β€” you can instead create a sample JSON that mimics the same structure (same keys, but with dummy values). That will be just as helpful for understanding the issue.

For example:

{
  "id": 123,
  "name": "Sample User",
  "email": "sample@example.com",
  "status": "active"
}

This way, we can work with the structure without needing your real data.

1 Like

Hi tomm, just checking in. I tested your code snippet above for calculating the days between each date and it looks like it should work. With this function you would get 0 days if the ship_date is after the build_date however, so it would be worth trying to swap the two and see if that fixes it.

Which code snippet did you test?

This one, although I modified it into a multiline JS query instead, and replaced the dates with my own data. Ex:

let s=moment("2020-01-16T21:03:19.554Z"), e=moment("2021-02-15T06:50:15.821Z"), c=0;
for(let m=moment(s); m.isSameOrBefore(e,'day'); m.add(1,'days')){ 
  let d=m.day();
  if(d!==0 && d!==5 && d!==6) c++;
} 
return c+' days';