Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Why does date-time Jira misc calculated field not work?

I've installed Jira Misc plugin. And I'd like to calculate date field, based on another custom fields.

I've created Number calculated field (Customfield_12695) to calculate number of days between two date fields:

<!-- @@Formula:  
  // Date1 -  issue.get("customfield_11295") 
 //  Date2  - issue.get("customfield_10151")
   (issue.get("customfield_11295") == null || issue.get("customfield_10151") == null ? null :
  (issue.get("customfield_11295").getTime() - issue.get("customfield_10151").getTime()) 
 / 1000 / 3600 / 24)

It works well.

Next I've tryed to create Date-time calculated field for calculate date based on values from created Customfield_12695 and two another custom date fields:

<!-- @@Formula:   (issue.get("customfield_11295") == null || issue.get("customfield_10151") == null || issue.get("customfield_11493") == null  ? null : 
  issue.get("customfield_12695").IntValue())) -->  

It doesn't work. I don't understand why...

I also tryed to create formula without another calculated custom field, but it's not working, becouse I can't pass integer argument for addDays(date, integer) function...

&lt;!-- @@Formula:   (issue.get("customfield_11493") == null || issue.get("customfield_10151") == null || issue.get("customfield_11295") == null ? null :
(issue.get("customfield_11295").GetTime() - issue.get("customfield_10151").GetTime()) / 1000 / 3600 / 24 ))

If I change expression (issue.get("customfield_11295").GetTime() -issue.get("customfield_10151").GetTime()) / 1000 / 3600 / 24 ) in this formula to integer number - it works.

Help me please to create correct formula for my use case.

I've tryed this variant from another Question, but it doesn't work too:

&lt;!-- @@Formula:long days(Date start, Date end) {
    Calendar c1 = GregorianCalendar.getInstance();
    int w1 = c1.get(Calendar.DAY_OF_WEEK);
    c1.add(Calendar.DAY_OF_WEEK, -w1 + 1);
    Calendar c2 = GregorianCalendar.getInstance();
    int w2 = c2.get(Calendar.DAY_OF_WEEK);
    c2.add(Calendar.DAY_OF_WEEK, -w2 + 1);
    //end Saturday to start Saturday 
    long days = (c2.getTimeInMillis()-c1.getTimeInMillis())/(1000*60*60*24);
    if (w1 == Calendar.SUNDAY) {
        w1 = Calendar.MONDAY;
    if (w2 == Calendar.SUNDAY) {
        w2 = Calendar.MONDAY;
    return days-w1+w2;
// Plan date of finish development - customfield_11493
// Plan date of publication for customer  - customfield_11492
// Date of agreement estimation time by cusomer - customfield_11295
// Date of customers notification - customfield_10151
if (issue.get("customfield_11493")==null || issue.get("customfield_10151") == null || issue.get("customfield_11295") == null)
  return null;
 return org.apache.commons.lang.time.DateUtils.addDays (issue.get("customfield_11493"), days(issue.get("customfield_11295"), issue.get("customfield_10151")))

But it doesn't work too :(.

1 answer

I've decided my problem described hear. There was problem in type of second argument of addDays() function. Decision is use intValue() in expression when calulated number of days for second argument.

This constuction is working now:

&lt;!-- @@Formula:(issue.get("customfield_11493") == null ? null : org.apache.commons.lang.time.DateUtils.addDays(issue.get("customfield_11493"), ((issue.get("customfield_11295").getTime()-issue.get("customfield_10151").getTime())/(1000*60*60*24)).intValue()))

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Industry Groups

🚗 How the Engineers at Karma used Atlassian products to build the Karma Revero

Hello, Automotive enthusiasts! Are you ready for October to begin 🙀? I wanted to share with you an Article I came across from Work/Life (The Atlassian blog) from Soumya Menon of Go2Group, a worldw...

38 views 2 1
View post

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you