Obtain the difference between two dates

Use case

Update a number field with the difference in days between two dates obtained from two Date Picker fields.

🗒️ Prerequisites

Set up the custom field

Create a Number custom field

Name: Time Difference

Add it to the screens of your choice.

🛠️ Configuration

Add the post functionUpdate fields to the transition of your choice.

Target issue*

Select current issue

Fields

Field*

Select Time Difference, the field previously created

Value*

Select Set field value manually (parser expression) and enter the following expression with the expression editor in Jira expression mode:

Bash
((new Date(issue?.customfield_10043  + "T00:00:00").getTime() - new Date(issue?.customfield_10040 + "T00:00:00").getTime())) / 1000 / 60 / 60 /24

Replace the field codes of the expression with the ones of your Date Picker fields.

With the current configuration, this expression will return the number of days between the first date and the second one. In order to display the number of hours, remove /24 from the expression.

Variation

If you prefer to use our parsing mode, you can set the expression editor to General mode and create an expression as follows:

Bash
%{({issue.cf10001}-{issue.cf10002})/1000 /60 /60 /24}

Do not forget to surround the operation with an additional %{}

Use case Workflow function Parser functions
Set the due date based on the priority

Update fields

getMatchingValue()

Obtain the difference between two dates

Update fields


Assign an issue to the user who last commented on it

Update fields


Add three days skipping weekends automatically to a Date Picker

Update fields


Keep parent's priority in sync

Update fields


Set the assignee based on the issue type

Update fields

getMatchingValue()

Set the fix version to affects version when resolving an issue

Update fields


Use the app user to update non-editable fields

Update fields


Automatically add incident reporters to problem tickets

Update fields

append()

fieldValue()

linkedIssues()

toStringList()

Copy labels of a sub-task to the parent issue upon closing

Update fields


Assign an issue to the project lead, if the issue is unassigned on creation

Update fields


Add watchers from another field

Update fields

Transition issue

union()

toStringList()

Add a sub-task's summary and key to the description of its parent

Update fields


Set a date field to a future date

Update fields

dateTimeToString()

Record an auditable timestamp of a Compliance Approval

Update fields

dateTimeToString()

Copy field values from epic to issues under it after creation

Update fields Transition issue

epic()

issuesUnderEpic()

filterByStatus()

Set a date field to the current date

Update fields

dateTimeToString()

Assign important issues to the project lead

Update fields


Set the priority to Highest if the 'Infrastructure' component is selected

Update fields


Background priority calculation

Update fields

avg()