Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How is the difference between dates in business days calculated?

Nadezhda Alshafi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 13, 2023

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!

2 answers

1 vote
Kristján Geir Mathiesen
Community Champion
March 13, 2023

Hi @Nadezhda Alshafi 

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

Nadezhda Alshafi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 13, 2023

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
 image.png

Kristján Geir Mathiesen
Community Champion
March 13, 2023

Sorry, then I am stumped :(

Kristján Geir Mathiesen
Community Champion
March 14, 2023

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:

datetime.png

Just like you. Seems like you are right, the businessDays function is somewhat wacky.

Maybe you can play around with:

{{[date].toBusinessDayBackwards}}

{{[date].toBusinessDay}}

{{[date].firstBusinessDayOfMonth}}

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

0 votes
Roy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 12, 2025

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.



Kristján Geir Mathiesen
Community Champion
March 12, 2025

Oh no, @Roy ! That might very well be a bug. I´ve flagged this. Hopefully Atlassian assistance will look at this soon.

Takk, KGM

Like Roy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2025

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

Roy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 13, 2025

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 -

Like # people like this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events