How to calculate two date fields and show the difference in days in number??

Fernanda de Souza Thaumaturgo
Contributor
October 4, 2020

Hi, 

I have two fields Date 1 and Date 2, I would like to subtract these fields for example {Date 1} - {Date 2} and return the value in days or number is it possible?
I have scriprunner and I'm trying to use it.

2 answers

0 votes
Will C
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.
October 7, 2020

This depends on what you are hoping to do with the returned value in days. this is a simple script you can run in the console that will give you the difference between the created and duedate in days

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager

IssueManager issueManager = ComponentAccessor.getIssueManager()

def issue = issueManager.getIssueObject("IssueKeyHere")

def dueDate = issue.getDueDate()

def createdDate = issue.getCreated()

dueDate - createdDate

Just remember that this might not work for custom fields as Jira stores them differently 

0 votes
Jack Brickey
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 4, 2020

You might find this similar post useful - How-to-calculate-number-of-days-between-two-system-fields 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events