Difference between the two dates, calculated in days
Asked by kalaimani:

Hello Community

My task involves calculating the difference between two dates: one is the issue creation date, and the other is a custom field that automatically populates when the issue transitions to 'Done.' How can I calculate the difference between these dates and, based on the number of days, update the value in a custom field?

We don't use Add-ons here


Answers:
author: Samuel Gatica
body: Hi [@kalaimani](/t5/user/viewprofilepage/user-id/5363035)

You can utilize automation to achieve this.

Please refer to [Date difference {{\[date1\].diff(\[date2\]).\[unit\]}}](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-difference---)

Example:

{{now.diff(issue.created).days}}

![Screenshot_3.png](https://community.atlassian.com/t5/image/serverpage/image-id/343263iF8318D33600F7C79/image-size/large?v=v2&px=999 "Screenshot_3.png")

Hope this helps!

Best regards

Sam

comments: author: kalaimani
body: Yes ,I tried it same way but i could not get as i expected.Can you help me with this.


author: Samuel Gatica
body: Hi [@kalaimani](/t5/user/viewprofilepage/user-id/5363035)

Could you please provide a screenshot that displays the details of your automation? Thank you.

Best regards

Sam


author: kalaimani
body: Hi [@Samuel Gatica](/t5/user/viewprofilepage/user-id/753028)

Test Date 2 is my custom field .

So, in my custom field, the difference in days between issue creation is automatically used to select the dropdown values.

For Example :If the difference between Test Date 2 and the issue creation date is 1, the automation will select dropdown value 1.

![Screenshot 2024-08-29 at 5.29.06?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/344506i164E41987B131E09/image-size/large?v=v2&px=999 "Screenshot 2024-08-29 at 5.29.06?PM.png")

![Screenshot 2024-08-29 at 5.26.23?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/344504i9F66E6B65E8AE254/image-size/large?v=v2&px=999 "Screenshot 2024-08-29 at 5.26.23?PM.png")


author: Samuel Gatica
body: Hi [@kalaimani](/t5/user/viewprofilepage/user-id/5363035)

Here is an example of how to update the dropdown field based on the outcome of the date difference calculation.

![Screenshot_4.png](https://community.atlassian.com/t5/image/serverpage/image-id/344583iCEB8DBD24D0E3778/image-size/large?v=v2&px=999 "Screenshot_4.png")

Hope this helps!

Best regards

Sam


author: kalaimani
body: Yes, it works for me. Great! Thanks for your help.

* Here What is meant abs ?
* If we have a small number of options, this method works. But if I have 200 dropdown values, is there an easier way to handle it?


author: Samuel Gatica
body: Hi [@kalaimani](/t5/user/viewprofilepage/user-id/5363035)

* *ABS* (expression), Returns the absolute (non-negative) value of the expression
* You can directly assign the result in the Select field as follows:

{{Test date.diff(issue.created).days.abs}}

![Screenshot_1.png](https://community.atlassian.com/t5/image/serverpage/image-id/344867i0AD528445D187803/image-size/large?v=v2&px=999 "Screenshot_1.png")

Best regards  
Sam


author: kalaimani
body: Great !! Yes its working .

Thanks again [@Samuel Gatica](/t5/user/viewprofilepage/user-id/753028)


author: Simon K?nig
body: Hi, without addons my suggestion is you could use Jira automation with smart values. Look them up here: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/>

And for SmartValue regarding date and time: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/>

You can cast any field-value as a smartvalue and then add them.

comments: author: kalaimani
body: Thank you sharing the Documents


Tags: automation

cloud

jira-cloud

smart-value