Forums

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

calculate difference between two dates

Channakesa Chindanur August 8, 2023

Hello,

I am trying to find out how to calculate the difference between two dates custom field and use the result to set another field number data type using JMWE set fields.

i was going some YouTube videos ( https://www.youtube.com/watch?v=9TKKHCckJD8) but in this required to install other addon, In my Jira environment we're using JMWE addon, i was thinking that if we use some scripts to create custom filed.

Let me know your suggestions please!

Thank you in advance

Regards,

Channakesa Chindanur

1 answer

1 vote
David Fischer
Community Champion
August 8, 2023

Hi @Channakesa Chindanur 

The advantage of using the JMCF app is that it allows you to create a new duration field (similar to, say, the "Original Estimate" field in terms of formatting), and that field will be updated automatically.

With JMWE, you'll be able to update a custom field with the difference between two dates, but:

  • the update will only take place either during a transition (using the Set Issue Fields post-function on a transition) or in response to an event (using the Set Issue Fields post-function in an event-based action)
  • the destination custom field can only be a standard Jira custom field type, and Jira doesn't offer a "duration" field type. You can use a number field if you want to show the difference between two dates as a number of days (or hours), or you could use a text field to format the duration to look like a Jira duration (e.g. "3d 4h 26m") but in that case sorting and searching won't work

I recommend using JMCF, but if you use JMWE, the value script will be the same. For example:

secondsBetween(issue.get("Start Date"), issue.get("End Date"))

which returns the difference as a number of seconds (you can always divide the results by 3600 to have a number of hours, or 86400 to have a number of days)

Channakesa Chindanur August 9, 2023

Hi David,

It looks like it'll help our requirement using above script in JMWE addon, but where do i need to add above script as in my env showing groovy template PFB.

it will be helpful if you can give right script to add.

 

Screenshot 2023-08-10 115119.png

Regards,

Channakesa Chindanur

Channakesa Chindanur August 10, 2023

O/p for above script, but still not reflecting in my Jira issue

Screenshot 2023-08-10 121101.png

David Fischer
Community Champion
August 10, 2023

As I mentioned earlier, this script is meant to be used either on a workflow post function such as the Set Issue Fields post function, on the transition where you set the End Date field, or on an event-based action that listens to changes to the End Date field. 

Please read the JMWE Server/DC documentation for details. 

Suggest an answer

Log in or Sign up to answer