These directions are demonstrated in the example workbook downloadable from the right-hand pane of this article. In this example, the work week is Monday to Friday, and the business hours are 8:15am to 5:15pm. Adjust calculations as needed for the desired business hours.
To exclude non-business minutes before opening and after closing, we can shift the the start date to the next opening time and the end date to the previous closing time.
IF DATEPART('weekday', [Start]) = 7 //if the start date is a Saturday
THEN
DATEADD('minute', 8*60 + 15, DATETRUNC('day',
//these expressions shift to opening time of 8:15am aka 8:15 on the 24hr clock
//adjust the interval to the desired open of business hours
DATEADD('day', 2, [Start])
//add two days to move to Monday
))
ELSEIF DATEPART('weekday', [Start]) = 1 //if the start date is a Sunday
THEN
DATEADD('minute', 8*60 + 15, DATETRUNC('day', DATEADD('day', 1, [Start])))
ELSE
MAX(
[Start],
DATEADD('minute', 8*60 + 15, DATETRUNC('day', [Start]))
)
//the MAX() aggregation will return whichever timestamp is last:
//the actual start time or the business opening time on the same day
END
IF DATEPART('weekday', [End]) = 7
THEN
DATEADD('minute', 17*60 + 15, DATETRUNC('day',
//these expressions shift to closing time of 5:15pm, aka 17:15 on the 24hr clock
DATEADD('day', -1, [End])
))
ELSEIF DATEPART('weekday', [End]) = 1
THEN DATEADD('minute', 17*60 + 15, DATETRUNC('day', DATEADD('day', -2, [End])))
ELSE MIN([End], DATEADD('minute', 17*60 + 15, DATETRUNC('day', [End])))
END
Next we need to remove non-business hours (i.e. the time after closing each day to opening the next day), as well as "business hours" on weekend days.
DATEDIFF('minute', [Start (shifted to opening)],[End (shifted to closing)])
//total minutes between start and end times
- DATEDIFF('minute', #4/3/2023 5:15 pm#, #4/4/2023 8:15 am#)
//find non-business minutes per day by finding the difference between the closing time
//on one arbitrary date and opening time on the next day
* DATEDIFF('day', [Start (shifted to opening)],[End (shifted to closing)])
//multiply by the number of days between Start and End to remove non-business minutes each day
- DATEDIFF('minute', #4/3/2023 8:15 am#,#4/3/2023 5:15 pm#)
* 2
* DATEDIFF('week', [Start (shifted to opening)], [End (shifted to closing)])
//for every week subtract the 'business hours' for 2 weekend days
[Business Minutes]/60
001456485
49 KB

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.