Calculating the difference between two dates in businessDays with a Date Time Picker field

Luz del Alba García Fabián
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!
February 6, 2025

Hi,

Have a problem when I calculated the difference between two dates in businessDays with a Date Time Picker field

Im trying this

 {{customfield_10XX1.diff(customfield_10XX2).businessDays}}

Begin customfield_10XX1 and customfield_10XX2  Date Time Picker fields

Ex:

customfield_10XX1 = Wednesday 05 Feb 08:00

customfield_10XX2 = Tuesday 11 Feb 18:00

This would be 5 business Days but the result of this is {{customfield_10XX1.diff(customfield_10XX2).businessDays}} = 4 

 

BUT If 

customfield_10XX1 = Wednesday 05 Feb 00:00

customfield_10XX2 = Tuesday 11 Feb 01:00 (any time after 00:00)

This {{customfield_10XX1.diff(customfield_10XX2).businessDays}} = 5 

I thought it isnt going to take time but apparently it does!

Can you help me?

 

I tried this too:

customfield_10XX1 = Wednesday 05 Feb 08:00

customfield_10XX2 = Tuesday 11 Feb 18:00

{{issue.customfield_10XX1.convertToTimeZone(issue.reporter.timeZone).diff(issue.customfield_10XX2.convertToTimeZone(issue.reporter.timeZone)).businessDays}} the result = 4

and 

{{issue.customfield_10XX1.jiraDate.diff(issue.customfield_10XX2.JiraDate).businessDays}} = blank, nothing

1 answer

0 votes
Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 2025

Hi @Luz del Alba García Fabián Welcome to the Community!

You may try below:

It converts your dates to midnight (00:00:00) before performing the diff calculation.

{{customfield_10XX1.startOfDay().diff(customfield_10XX2.startOfDay()).businessDays}}

 If it does not work then try.

Assuming an 8-hour workday, this converts total work hours into business days.

{{customfield_10XX1.diff(customfield_10XX2).hours.divide(8)}}

 

Luz del Alba García Fabián
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!
February 7, 2025

The second option doesn't work because has a weekend between the dates

The first option didn't work either because for some reason businessDays didnt take the day in course but you give me an idea and I try this


{{issue.customfield_10XX1.convertToTimeZone(issue.reporter.timeZone).toStartOfDay.diff(issue.customfield_10XX2.convertToTimeZone(issue.reporter.timeZone).toStartOfDay.plusDays(1)).businessDays}}

Setting the start of day to have control of the hours and plus 1 in the end date day to it takes the day of end too. Seens to work,

BUT  in this scenario doesn't work, and I don't know why 

customfield_10XX1 = Monday 03 Mar 00:00

customfield_10XX2 = Fiday 07 Mar 23:30

2025-03-03T00:00:00.0+0100 - 2025-03-08T00:00:00.0+0100 = 4 
like why???

Luz del Alba García Fabián
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!
February 7, 2025

The second option doesn't work because has a weekend between the dates

The first option didn't work either because for some reason businessDays didnt take the day in course but you give me an idea and I try this


{{issue.customfield_10XX1.convertToTimeZone(issue.reporter.timeZone).toStartOfDay.diff(issue.customfield_10XX2.convertToTimeZone(issue.reporter.timeZone).toStartOfDay.plusDays(1)).businessDays}}

Setting the start of day to have control of the hours and plus 1 in the end date day to it takes the day of end too. Seens to work,

BUT  in this scenario doesn't work, and I don't know why 

customfield_10XX1 = Monday 03 Mar 00:00

customfield_10XX2 = Fiday 07 Mar 23:30

2025-03-03T00:00:00.0+0100 - 2025-03-08T00:00:00.0+0100 = 4

Suggest an answer

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

Atlassian Community Events