Hello,
I created an Automation Rule to calculate the total months between start and end date fields and then store the result in a Customfield.
How can I round the number of months ? because I got a wrong result, 1 month is missing.
This is my smart value:
{{issue.end date.diff(issue.start date).months.abs}}
Thank you,
Nouha
Hi @NUH
For a question like this for diff() not working as expected, please provide the example date values, the result returned, and what you expected to happen. That will provide context for the community to offer better suggestions.
Until we see those...
The date / time function diff() only returns integer values in the units of measure selected (e.g., months). Depending on the units, it may use floor, ceiling, or rounding adjustments.
To take control of the difference and explicitly round to the desired precision, you could do this:
For example, to do this for rounded days from seconds to 2 decimal places, where 86400 is the number of seconds in a 24h day:
{{#=}} round( {{issue.dateA.diff(issue.dateB).seconds}} / 86400, 2) {{/}}
The challenge for your scenario is your units are months, and those have a variable number of days per month. And so seeing the specific date values you are using may indicate what is happening.
Kind regards,
Bill
When I try that same smart value expression with two date fields it works and returns 12 months.
Let's try this to help diagnose what is happening:
start date: {{issue.start date}}
end date: {{issue.end date}}
end date plus 1: {{issue.end date.plusDays(1)}}
This will confirm if your smart values are correct and if there are potentially multiple fields with the exact same names (and so which are confusing the rule processing).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Bill,
With the previous dates provided I am getting the correct result using plus 1 function, but if start/end dates changes how can I handle to round months ?
For the following example : I would like to count January to have 13 months as total
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that additional example to help clarify the need: you want to count the months difference including the end points (rather than just the difference in month values for the dates).
One solution approach is to change the end date to the endOfMonth first and then increment by one day. That will handle differences in the number of days per month.
{{issue.Start date.diff(issue.end date.endOfMonth.plusDays(1)).months}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @NUH
Welcome to the Atlassian community.
Use the round function.
https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#Round
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.