---
title: "Calculate the number of working days between two dates"
canonical: "https://support.appfire.com/space/JMCF/465666501/Calculate%20the%20number%20of%20working%20days%20between%20two%20dates"
format: markdown
---
> Macro (aura-html)

### Abstract

This code snippet calculates the number of days between two dates excluding the weekends. By default, when you calculate the difference the weekends are included. To exclude them, you can use this snippet.

### Logic

- Fetch the dates
- Run a loop to add a day each until the number of remaining days - Skip if the day is a "Saturday" or a "Sunday"
- After adding the days, skip the end if it is a weekend
- Clear the time and return the date

### Snippet

```groovy
Integer workDaysBetween(Date from, Date to) {
  if (from == null || to == null)
    return null;
  Calendar startCal = Calendar.getInstance();
  Calendar endCal = Calendar.getInstance();
  startCal.setTime(from);
  endCal.setTime(to);
  int numberOfDays = 0;
  startCal.upto(endCal) {
    startCal.add(Calendar.DAY_OF_YEAR, 1);
    if (startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY
       && startCal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)
         numberOfDays++;
  }
  return numberOfDays;
}

workDaysBetween(issue.get("date1"),issue.get("date2")) //between two date fields
workDaysBetween(issue.get("date1"),new Date()) //between one date fields and now
```

### Placeholders

| **Placeholder** | **Description** | **Example** |
| --- | --- | --- |
| `<from`> | <span style="color: #333333">Date to which the number of days should be added</span> | `new Date()` |
| `<nod>` | Number of days to add | `22` |

Examples

The output of this code snippet is a [Timestamp](http://docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html) which you could use in a Groovy script, for example, to:

- Calculate and display the Due date plus 5 days, excluding weekends, in a Calculated Date/Time field
- Calculate the time to resolution excluding weekends and display a message to the customer in a Calculated Text field

### References

- [issue variable](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465732169)
- [Accessing the fields of an issue](https://appfire.atlassian.net/wiki/spaces/JMCF/pages/465371580)
- [**Groovy Documentation**](http://groovy.codehaus.org/User+Guide)

### Related articles

> Macro (contentbylabel)

> Macro (details)
> 
> | **Related issues** |  |
> | --- | --- |