# Define business hours

**URL:** <https://community.dynatrace.com/t/define-business-hours/40002>\
**Category:** DQL\
**Tags:** dql\
**Created:** [May 31, 2023, 2:00pm UTC](https://community.dynatrace.com/t/define-business-hours/40002 "2023-05-31T14:00:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sinisa\_zubic](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/sinisa_zubic/32/32498_2.png) [@sinisa\_zubic](https://community.dynatrace.com/u/sinisa_zubic)\
**Post date:** [May 31, 2023, 2:00pm UTC](https://community.dynatrace.com/t/define-business-hours/40002/1 "2023-05-31T14:00:51Z")

</div>

Hi Team,

how could I define business hours with DQL? I looked at filtering on the timestamp but can’t really find a way. For example: for monday to friday, 08am to 7pm.Best,  
Sini

---

<div class="post-metadata">

**Author:** ![educampver](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/educampver/32/29917_2.png) [@educampver](https://community.dynatrace.com/u/educampver)\
**Post date:** [June 1, 2023, 6:39am UTC](https://community.dynatrace.com/t/define-business-hours/40002/2 "2023-06-01T06:39:01Z")

</div>

Hi Sinisa, the Notebooks app has a snippet for this use case:

 ![Screenshot 2023-06-01 at 8.37.21 AM.png](https://global.discourse-cdn.com/dynatrace/original/2X/e/ef3ac5e936836e97d3b7a6592a2c1b8f7c3c9b35.jpeg)

Here’s the query anyways:

```markup
fetch bizevents, from:now()-7d, to:now()
| fieldsAdd hour=toLong(formatTimestamp(timestamp,format:"H")), day_of_week = formatTimestamp(timestamp,format:"EE")
| filterOut day_of_week == "Sat" or day_of_week == "Sun" // Remove weekend days
| filterOut hour <= 5 or hour >= 15 // Remove everything that is not between 5am and 3pm

```

---

<div class="post-metadata">

**Author:** ![gdalessandro](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/gdalessandro/32/5318_2.png) [@gdalessandro](https://community.dynatrace.com/u/gdalessandro)\
**Post date:** [January 6, 2026, 4:41pm UTC](https://community.dynatrace.com/t/define-business-hours/40002/3 "2026-01-06T16:41:18Z")

</div>

How would you do this using the timeseries command (using metrics)?

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [January 8, 2026, 6:04pm UTC](https://community.dynatrace.com/t/define-business-hours/40002/4 "2026-01-08T18:04:39Z")

</div>

I would suggest to use&nbsp;_**getHour()**_ and _**getDayOfWeek()**_ functions instead of _**formatTimestamp()**_ and conversion.

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [January 8, 2026, 6:15pm UTC](https://community.dynatrace.com/t/define-business-hours/40002/5 "2026-01-08T18:15:47Z")

</div>

For timeseries you can also use&nbsp;_**getHour()**_&nbsp;and&nbsp;_**getDayOfWeek()**_ functions, but you need first timestamps of particular buckets using _**start()**_ funtion, so you can filter out irrelevant values:

```markup
timeseries {d=avg(dt.host.cpu.usage), timestamp=start()}, interval:1h
| fieldsAdd d = if(getHour(timestamp[])>=7 and getHour(timestamp[])<=16 and not in(getDayOfWeek(timestamp[]), {6,7}) , d[])
| fieldsRemove timestamp

```

 ![krzysztof_hoja_0-1767896117650.png](https://global.discourse-cdn.com/dynatrace/original/3X/2/e/2ea0d4376f36a76f07c03a57107f14054dc4607f.png)

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [January 9, 2026, 11:59am UTC](https://community.dynatrace.com/t/define-business-hours/40002/6 "2026-01-09T11:59:27Z")

</div>

While this works for “common cases”, it’s much more difficult to implement a calendar-based business hours considering, for example, holidays during working days or other events.

One approach I still use with customers is a “calendar metric” representing business availability and then you can use it in the DQL to filter by multiplication.

See details of it in this [post](https://community.dynatrace.com/post/240367#M153)&nbsp;. Even though this was originally developed for classic metrics for SLO calculation purposes, it can be used with DQL / Grail in the very same way.

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [January 9, 2026, 12:19pm UTC](https://community.dynatrace.com/t/define-business-hours/40002/7 "2026-01-09T12:19:50Z")

</div>

Yes, if you have fact of being in or out of business hours ingested in Grail as indpendent timeseries, you can use it to filter any other timeseries with data,
