Forums

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

How do I calculate the duration in days, hours, minutes, between two other custom date fields?

Eli Devlin
Contributor
February 22, 2023

I have two custom fields, both are date and time pickers.

I would like to be able to calculate the duration of time between the two fields and express it as a third custom field.

I'm currently using a crude automation rule which edits the 'duration' field when the start or end fields are edited, with the value: {{customfield_10999.diff(customfield_11251).hours}}

This returns a number in hours. I could also set it to .days.

But is there a way to return it in minutes, if less than X minutes, hours, if less than X hours, and otherwise days?

Also, which field type would be best for the 'duration' custom field?

Thank you in advance!!

 

EDIT: I have discovered that simply removing the unit displays the time in all units, as seen here: {{customfield_10999.diff(customfield_11251)}}

However that just leaves the ideal Field Type to use to house this information. I have created a custom field with the Time in Status type, but this field doesn't show up as a target for Edit Field in Automation rules.

Is there a better custom field type to display a time duration?

1 answer

1 accepted

5 votes
Answer accepted
Omar Mohamed Fathi
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.
February 23, 2023

1. create a numeric field called ( number of days or number of hours for example ) 

2. create a date picker field ( call it date 1 and memorize its id number for example lets say its number is 123 ) 

3. create a date picker field ( call it date 2 and memorize its id number for example lets say its number is 345 ) 

Now create an automation rule 

trigger issue field value changed or transition to done for example  

actions - edit issue field - choose field date 1 and set the value 

{{now}}

 

trigger issue created 

actions - edit issue field - choose date 2 field and make it to copy from Resolved field

action - edit issue field - choose field number of hours and make it this value 

{{issue.customfield_123.diff(issue.customfield_345).hours}}

don't forget to change the fields ids according  to you also change the triggers according to your requirements you can also make it days instead of hours 

Osama February 23, 2023

worked for me

Eli Devlin
Contributor
February 23, 2023

Thanks Omar, that's really helpful

I decided to use {{customfield_10999.diff(customfield_11251)}}

Without .hours or .days on the end, it actually displays all units.

e.g. 3 days 21 hours 31 minutes,

Thank you!

Suggest an answer

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

Atlassian Community Events