Jira + ScriptRunner: Update a Custom Field with Difference between Two Dates


You have a start date and an end date within an issue in Jira. On some cases, you may want to capture the elapsed number of days between those two dates (to calculate effort to complete the task, for example). This guide uses ScriptRunner to calculate the elapsed days between any two dates and add that value into a custom field. You can then use this field in any of your reports.

Cover photo by JESHOOTS.COM on Unsplash


  • Information from Jira
    • The Jira workflow to embed the script
    • The custom field name and its option IDs
    • The Date Fields to be used for comparisons
  • ScriptRunner for Jira
  • Groovy script to execute

Script to Calculate and Update Field with Difference between Two Dates

You can grab the script from my repository here: ValidateTwoDatesWorkflow.groovy @ Bitbucket

Configuration in Jira

In the workflow for the project, I added a new Custom Script post function to the Resolve Issue transition: