Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


How do I exclude weekends from this script I found on the Adaptavist library

Tim Perrault
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Nov 14, 2023



Server and App details:

Jira Data Center Installed version: 8.22.6

Adaptavist ScriptRunner Installed version: 8.14.0


I found this script on the adaptavist library and it works great. Is there a way to exclude weekends from the duration? Any help would be appreciated as I'm not that great at coding. script below:

import com.atlassian.jira.component.ComponentAccessor

import java.sql.Timestamp

import java.time.temporal.ChronoUnit

// Get the required component

def customFieldManager = ComponentAccessor.customFieldManager

// The name of the lower date custom field

final String lowerDateCustomFieldName = "Start Date/Time"

// The name of the higher date custom field

final String higherDateCustomFieldName = "Resolution Date/Time"

// Get the custom field objects

def lowerDateCustomField = customFieldManager.getCustomFieldObjects(issue).find { == lowerDateCustomFieldName }

def higherDateCustomField = customFieldManager.getCustomFieldObjects(issue).find { == higherDateCustomFieldName }

if (!lowerDateCustomField || !higherDateCustomField) { "Could not find one ore more of the provided custom fields"

    return null


// Get the date values from both issues

def lowerDateValue = issue.getCustomFieldValue(lowerDateCustomField) as Timestamp

def higherDateValue = issue.getCustomFieldValue(higherDateCustomField) as Timestamp

// Transform both values to instants

def lowerDateInstant = lowerDateValue?.toInstant()

def higherDateInstant = higherDateValue?.toInstant()

// Change the chrono unit to obtain the difference in other time unit.

final chronoUnit = ChronoUnit.SECONDS

// Calculate the difference between the lower and the higher date.

lowerDateInstant && higherDateInstant ? chronoUnit.between(lowerDateInstant, higherDateInstant) : null

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 14, 2023

Hi @Tim Perrault

If you want to exclude Saturday and Sunday from the date range, you could try something like this:-

import java.time.LocalDate
import java.time.DayOfWeek

int countDaysWithoutWeekend(LocalDate startDate, LocalDate endDate) {
int count = 0

for (def date = startDate; date.isBefore(endDate.plusDays(1)); date = date.plusDays(1)) {
// Check if the current date is a weekend (Saturday or Sunday)
if (date.dayOfWeek != DayOfWeek.SATURDAY && date.dayOfWeek != DayOfWeek.SUNDAY) {

def start = LocalDate.of(2023, 1, 1)
def end = LocalDate.of(2023, 1, 10)
int daysWithoutWeekend = countDaysWithoutWeekend(start, end)
log.warn "Number of days between $start and $end (excluding weekends): ${daysWithoutWeekend}"

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Once you have included the method above, you can use it to calculate the total number of working days for the date range you have provided, i.e. excluding the weekend.

I hope this helps to solve your question. :-)

Thank you and Kind regards,


Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events