Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I want to calculate the difference b/w 2 date fields in hours

Pradeep Khatri June 9, 2020

Hi,

 

I want to generate a report where i need to calculate the difference between 2 date fields ( created date and updated date that should display the answer in hours . Can you please help how do i achieve that ?

 

Thanks,

Pradeep

2 answers

0 votes
Anand Chittoor November 1, 2021

Hello John.. same problem. I am trying to get the difference between 2 custom fields (timestamp) and save them into a 3rd custom field (number) using Automation (jira cloud).

This is for ensuring we meet internal SLOs...

{{issue.customfield_14474.diff(issue.customfield_14475).businessDays}}

The 3rd custom field is on the screen but does not show any number when the automation rule is triggered effectively.

0 votes
John Funk
Community Champion
June 9, 2020

Hi Pradeep - Welcome to the Atlassian Community!

Here is what I use for one of my use cases:

{{issue.customfield_17152.diff(issue.customfield_16921).days}}

You could replace days with hours and see what happens - I have not tried to use hours before.  :-)

John Funk
Community Champion
June 9, 2020

Sorry - I should have mentioned that I created an Automation For Jira rule that updates a custom number field with the value generated by the DIFF statement. 

Pradeep Khatri June 9, 2020

hi John,

Thanks for your reply , i am newbee to this so apologies if i ask dumb questions,  where do i write the above script , we use Jira Service Desk here at home office and how do you create automation for JIRA rule?

 

Thanks,

Pradeep

John Funk
Community Champion
June 9, 2020

No worries!

  1. Go to Project Settings > Project Automation (on left-hand menu)
  2. Press Create Rule in top-right corner
  3. Select the Trigger "Field Value Changed" and press Save
    1. Select one of the fields (probably updated date)
  4. Next Select to add an Action, and choose "Edit Issue"
  5. Select the custom number field you have already created to store the hours
  6. Use the code I provided above but switch out my custom fields for created and updated and press Save
  7. Name your Automation and turn it on

Now when each issue is created, it will add the desired default label as long as the issue is created in that project. You might need to refresh the page after each issue creation to see it.

You can do this via global rules to apply to all projects also. You'll need to be a Jira Admin/Site Admin, then instead of going to Project Settings, go to Jira Settings (cog icon on left-hand navigation bar) > System > Automation Rules (left-hand menu).

For more on using Automation For Jira see these help pages.

Pradeep Khatri June 9, 2020

Hi John,

I don't see step 3 in my view when i press create Rule . can you please advise what i am missing here and somehow i am not able to attach a pic to this comment :(

Thanks,

Pradeep

John Funk
Community Champion
June 9, 2020

Can you post a screenshot of what you see for step 3?

Pradeep Khatri June 9, 2020

 

i don't know whether it's my HO laptop , not able to attach screenshot here. :(

John Funk
Community Champion
June 9, 2020

Try to start the process with this URL:

https://YourDomain.atlassian.net/plugins/servlet/ac/com.codebarrel.addons.automation/cb-jira-automation-rules#!/

But replace YourDomain with your actual. 

Then start with No. 1 again and see if you see Field Value Changed available in Step 3. 

Pradeep_Khatri June 9, 2020

attached is the view I get John. 

 

JIRAAutomationRule.PNG

John Funk
Community Champion
June 9, 2020

No, that's not Automation for Jira - that looks like maybe Jira Service Desk automation. Did you use my link above?

Pradeep Khatri June 9, 2020

yes, i only have access to JIRA Service Desk Automation , i tried your link but it  says  I don't have access to the page, any advise on how the above can be achieved in JIRA Service Desk.

John Funk
Community Champion
June 9, 2020

See if your Jira Administrator can help you out. 

Suggest an answer

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

Atlassian Community Events