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

Fernando Passos May 8, 2020

Hi, 

I have two fields Date A and Date B, I would like to subtract these fields for example {Date A} - {Date B} and return the value in days or number is it possible? in the example above I use the number value and string value and the result is not as expected. I'm using the JWT CAlculated Number.

Result: Calculated Date-Time

Data A: 08/May/20
Data B: 09/May/20
Data Total: 31/12/69 21:00

Result: Calculated Number Field

Data A: 08/May/20
Data B: 30/May/20

           Data Total N : 0

3 answers

1 accepted

6 votes
Answer accepted
Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 10, 2020

Hi @Fernando Passos ,

given your two fields and assuming Date B is the larger one, the expression should look like:

round({bbbbb} - {aaaaa}) / {DAY}

Please replace aaaaa and bbbbb with the field codes for Date A and Date B.

Since you might want to ensure that the calculation will only be executed if both fields are set, I'd recommend the following expression:

{aaaaa} != null AND {bbbbb} != null ? round({bbbbb} - {aaaaa}) / {DAY} : null

Cheers
Thorsten

Fernando Passos May 12, 2020

Hi @Thorsten Letschert _Decadis AG_ ,

Perfect! I had the result I expected, thank you very much.

Fernando Passos May 12, 2020

I used this one. round ({Data B} - {Data A}) / {DAY}

Like Pitty likes this
Abulfaz Shukurov July 30, 2021

Thank you very much!

6 votes
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2020

Hi Fernando,

I use Automation For Jira to do that. I created a number field then populate it with this:

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

Fernando Passos May 8, 2020

Hi John,

Thanks for the help, but we don't have automation for jira in the company, we have script runner, behavior and the JIRA workflow Toolbox. Can we achieve this result with the add-ons we have?

Like Hugo Oliveira likes this
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2020

I don't use any of those. You would need to contact their support directly. Sorry. 

Fernanda de Souza Thaumaturgo October 4, 2020

@John Funk It worked perfectly, thank you very much!!

Like # people like this
Stephanie Loraine Garrido Brito October 20, 2023

Hello! @John Funk 

It seems you are using the custom fields id?

Where can I find them?

Thanks in advance

1 vote
Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2020

Hi @Fernando Passos 

 

Please check Adaptavist Script runner library - https://library.adaptavist.com/

 

There you can find helpful scripts ready to use, e.g. - https://library.adaptavist.com/entity/calculate-the-difference-between-two-dates

 

Regards,

Sebastian

Fernando Passos May 8, 2020

Hi @Sebastian Krzewiński

Thanks, I'll check and return. 

Like Sebastian Krzewiński likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.7.0
TAGS
AUG Leaders

Atlassian Community Events