I am using this formula for a calculated custom field (duration date calculation).
I need the number of "days" that has passed since a date. In my case the custom field "Race Handover" is a date that we insert manually, and I need to see each day, how many days have passes since the handover date.
Here is what I put in the formula:
secondsBetween(issue.get("RACE Handover"), new Date(), "days" )
But what I am getting in Jira is the duration in Weeks format
so it shows: "26 weeks"
instead I would like to get: 182 days.
I wonder if you can help me understand how to change the format of the duration from weeks to days.
Thanks.
Hi @Shiva Jamei
unfortunately, you cannot control the formatting of Calculated Duration fields. If you always want to display the duration in weeks and weeks only, whether the value is 1s (-> 0 weeks) or 10 years (-> 520 weeks), then you should create a calculated Number field and have it return the number of weeks between the two dates:
secondsBetween(issue.get("RACE Handover"), new Date(), "weeks" ) / 3600 / 24 / 7
and then use the formatting option to display:
$value weeks
Thanks @David Fischer I have created the calculated number field
This is the formula that I put:
secondsBetween(issue.get("RACE Handover"), new Date(), "weeks" ) / 3600 / 24 / 7 * 7 and here is the output:
In RACE since: [The old field to calculate the duration]
23 weeks, 2 days
RACE duration days: [The new field ]
161
So it is getting the 23 weeks and showing 23*7 as 161 days, but it is not adding the "2days", so I expect to see 163 days instead of 161.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's because, at the end, you divide by 7 and then multiply by 7. That rounds up the value to whole weeks. Just remove /7*7 at the end.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is what I get then by this:
secondsBetween(issue.get("RACE Handover"), new Date(), "weeks" ) / 3600 /24
In RACE since: 19 weeks, 1 day
RACE duration days: No such property: weeks for class: script16668541552001129910092
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure you didn’t remove the double quotes around weeks ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's the format expression that's incorrect, it should be a valid groovy expression. Try this:
"$value weeks"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, this is becoming interesting, I change the format, and now I get: 133.0 weeks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you need weeks, the value should return a number of weeks, so you should add /7 to the formula.
As for not displaying the ".0", in the format expression, try this:
"${(int)value} weeks"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @David Fischer
It is fixed now, I did not wanted it in weeks as the original field is already in weeks and I wanted the new calculation in Days, so I just replaced weeks in days and now I get the correct number!
which is
Thanks a lot!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Shiva Jamei
Here is an example of a script from the adaptavist library:
Or If you have automation for jira, you can create the following rule. You could include a trigger that runs every day at 9:00 am (for example) and enter a JQL that contains all issues that need to be updated. (or the trigger you already have included in the rule)
To calculate how many days have passed since the Handover Date you can include the following formula where customfield_XXXXX is your Handover Date field:
{{customfield_XXXXX.diff(now).days}}
I hope it helps,
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Paloma,
I have tried the adaptivist formula, but it didn't work, I don't know if it is compatible with "JMCF" scripts.
This is the custom field that I am actually using now and in the groovy script I put "secondsBetween(issue.get("RACE Handover"), new Date(), "days" )"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.