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

Calculate time difference between custom date fields

Sir Be Apr 07, 2014

I have 2 custom date fields (start and end time).

I want to calculate the difference between them.

The difference has to be greater than 4hours.

This will be set in a workflow as a condition/validation when creating an issue.

Working in jira 4.2, standalone version

Downloaded and installed a lot of plugins, none give me the result i wanted

(1 of my conditions if end time has to be larger or equal than begintime)

4 answers

1 accepted

3 votes
Answer accepted


I think that you can do this by adding a condition to the transition using one of the scripting utilities plugin like script runner or jjupin, jss.. or develop you own plugin.
Look to this links its can help you and give you more ideas.

In our company, we use JJUPIN to do like what do you need.

Sir Be Apr 09, 2014

I'm testing some script writers.

JJupin will be the best, except ..


try this code as a condition in yur transition workflow

replace sDate with your custom field start date and eDate with your customfield end date

date #{sDate} ="2014-04-10 12:00:00";// start date time
date #{eDate}="2014-04-10 16:30:00";//end date time
number #{diffTime}=0;
return true;
return false;

Sir Be Apr 09, 2014

Put it as validator when creating an issue
Script workflow function : Simple scripted validator : Checks script

i get always the error message :s

Timedifference between the 2 has to be at least 4 hours.
So if startdate is today at noon and enddate is tomorrow at noon, it's ok.

But it's a good start ty.

What are the possible languages to write the script in?

Sir Be Apr 09, 2014

Ok, shall search and try so.
I will keep you all informed.


jjupin is a paid plugin but it's very easy to work with it (don't have knowledge in java language)

groovy and jss are free plugins but it's hard to work with it, ithink that you must have some knowledge in java or python languages

If this answer or other answers to your questions have helped you, please can you accept answers to help other who has the same problems

good luck

Sir Be Apr 10, 2014

Java is no problem, but scripting is.

Thank you.

Sir Be Apr 13, 2014

Even when the script is - in the simple script validator-:

Script workflow function : Simple scripted validator : Checks script:

date sDate = cfValues['Start time'];// start date time
date eDate = cfValues['End time'];//end date time
number diffTime=0;
return true;
return true;
return false;
I still get the error message...
What's the syntax for custom fields? 
cfValues['CF name'] or cfValues['CF ID']
1 vote
Tuncay Senturk Community Leader Apr 07, 2014

Hi Bert,

Do you just need a custom field to calculate time difference between two custom date fields? Or you need a workflow condition/validation to calculate difference and set your workflow accordingly?

If you raise an issue describing the details, I can add such a feature to Enhancer Plugin ASAP.

Tuncay Senturk

Sir Be Apr 07, 2014

A user may not be able to create an issue if the timespan between start and end date(time) is less than 4h.

The difference don't have to be stored, it may be calulated when the user wants to create the issue.

So custom field not necessary, prefer the condition/validation

btw: TY :D

Tuncay Senturk Community Leader Apr 07, 2014


Sorry but it is not clear for me.

How will those custom fields be calculated, if there is no issue?

I mean, custom fields are located in an issue, but you want to calculate according to two custom fields.

My question, where will these fields take place, so that workflow condition will check for them?

Sir Be Apr 07, 2014

Including a prt scr for some clarification
When an user wants to create an issue, they have to fill in the start and end date.

If they click on 'create', a message will appear if the difference between those 2 is less than 4 hours.
(like now, except my condition is wrong)

(gd, why cant i upload a picture? ><)

old fashion way:

Tuncay Senturk Community Leader Apr 07, 2014

Hmm, I got the point now. It will do a validation according to user inputs.

By the way, I have just seen that you are using JIRA 4.2

I am sorry, it is impossible to implement a feature to support JIRA 4.2

Sorry again


Sir Be Apr 07, 2014

Nor problem, thanks anyway for your time and interest.

JIRA 4.2 is my problem, it's not so supported anymore.
We are slowly upgrading to a 6 version (atm only for testing), but we work on JIRA 4.2

0 votes
Stephen Hayden Nov 12, 2015

SIL custom field, use this script:


interval age = currentDate() - created;
return "This issue is " + age + " old";


replace currentdate() and created with customfield_000000 where 00000 = the custom field IDs.

0 votes
CelesteCS Jun 08, 2016


For any calculations in Confluence, including any manipulations with table data, you may use CelesteCS Math for Confluence.

Assume you have a table with three columns and three rows on your page – from A1 till C3, where row 1 is the header row. The sum calculation formula for rows 2 and 3 will be simple:


There is a plenty of other functions in the macro, so you may perform any calculations using formulas in EXCEL style.



Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in United States

Topic Tuesday: Agile

Another week, another Topic Tuesday!  Agile has been on my mind a lot lately because I've seen good implementations and bad implementations, but now as a Jira admin it matters more to me whether...

17 views 0 0
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