I am trying to calculate the difference between two dates in business days and it seems to me, that it would be logical to calculate the difference in full business days. This is how it works with calculating the difference in calendar days, at least.
For example:
date1 = 2023-03-09 15:00:00.0 (Thursday)
date2 = 2023-03-13 10:00:00.0 (Monday)
the expression {{date1.diff(date2).days}} returns "3", as expected. It is how many full days have passed.
however, the expression {{date1.diff(date2).businessDays}} returns "2".
But I am expecting it to return "1", because it would be the amount of full business days between the dates. Considering Saturday and Sunday are not business days.
If someone could clarify the logic behind calculating difference in business days, it would be very helpful.
Thank you in advance!
According to this page, BusinessDays -> business days are considered to be Monday to Friday, 9am to 6pm.
Could the time zone of your instance be tripping this up?
HTH,
KGM
Hi, @Kristján Geir Mathiesen !
Thank you for your answer, but unfortunately this doesn't seem to clear things up for me. I still can't quite understand how the difference is calculated. Does it not consider the "time" part of the date, rather only the "date" part?
I believe, the time zone is not the issue, the dates are in the same time zone. Full dates look like this:
date1 = 2023-03-09T15:00:00.0+0000
date2 = 2023-03-13T10:00:00.0+0000
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.
Hi again @Nadezhda Alshafi
For {{created.diff(updated).days}} I get 3
For: {{created.diff(updated).businessDays}} I get 2
The date and time stamp on the ticket is:
Just like you. Seems like you are right, the businessDays function is somewhat wacky.
Maybe you can play around with:
to see if you can figure it out. Just an idea...
Also, is the time zone in your user profile the same as the time zone of the instance?
HTH,
KGM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nadezhda Alshafi @Kristján Geir Mathiesen
Sorry for digging up this discussion but I couldn't find anything similar. I've tested both ends of this function in a lookupissue:
When you print {{created}} and {{created.tobusinessdays}} it will show the correct dates:
2025-02-17T08:03:21.3+0000 - 2025-02-17T08:03:21.3+0000
2025-02-16T08:32:41.9+0000 - 2025-02-17T08:32:41.9+0000
2025-02-15T21:06:28.8+0000 - 2025-02-17T21:06:28.8+0000
2025-02-14T07:46:06.1+0000 - 2025-02-14T07:46:06.1+0000
2025-02-13T16:25:00.9+0000 - 2025-02-13T16:25:00.9+0000
However, I needed this to calculate if a specific date is IN a weekend or not, so I try the difference and if it does'nt equal 0, do something. My results are as follows, using the following smart value {{Created.diff(Created.toBusinessDay).days}} :
2025-02-17T08:03:21.3+0000 - 23
2025-02-16T08:32:41.9+0000 - 24
2025-02-15T21:06:28.8+0000 - 24
2025-02-14T07:46:06.1+0000 - 26
2025-02-13T16:25:00.9+0000 - 26
Looks like this is a bug, when you use the "diff" function together with "tobusinessdays" it starts to calculate off the actual ticket createdate, instead of using the supposed date off the ticket in the lookupissue iteration. The ticket I am building from is created at March 11, 2025 at 3:55 PM.
I am running the automation on a non-related ticket to catch issues which are out of the businessdays & businesstimes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh no, @Roy ! That might very well be a bug. I´ve flagged this. Hopefully Atlassian assistance will look at this soon.
Takk, KGM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Roy -- Welcome to the Atlassian Community!
There are known defects with math operations inside of list iterators, including date / time diff() within Lookup Issues iteration, where it uses the wrong fields in the operations. That can cause all kinds of problems!
Please review these to learn how they align to the symptoms you see:
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kristján Geir Mathiesen
Thanks for flagging the ticket!
Hi @Bill Sheboy Thanks for pointing those tickets out to me, exactly matches what I am experiencing also.
What I do find interesting is that the following smart value does work in the iteration to see which issues are outside of work hours:
{{#lookupIssues}}
{{created}} - {{#if(or(created.format("yyyy-MM-dd").toDate.diff(created).minutes.lt(360),created.diff(created.plusdays(1).format("yyyy-MM-dd").toDate).minutes.lt(360)))}}{{Key}}{{/}}
{{/}}
2025-02-17T09:08:36.9+0000 -
2025-02-17T08:57:49.3+0000 -
2025-02-17T08:03:21.3+0000 -
2025-02-16T08:32:41.9+0000 -
2025-02-15T21:06:28.8+0000 - TICKET-32918
2025-02-14T07:46:06.1+0000 -
2025-02-13T16:25:00.9+0000 -
2025-02-13T14:07:28.0+0000 -
2025-02-13T08:15:16.5+0000 -
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.