# TIPS - DQL Timeframe selection

**URL:** <https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655>\
**Category:** Dynatrace Tips\
**Tags:** dql, timeframe, tips-and-tricks\
**Created:** [November 16, 2023, 1:21pm UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655 "2023-11-16T13:21:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gbaudart](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@gbaudart](https://community.dynatrace.com/u/gbaudart)\
**Post date:** [November 16, 2023, 1:21pm UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655/1 "2023-11-16T13:21:42Z")

</div>

I’m taking the liberty of sharing this tip because I’ve seen several people share difficulties in selecting a specific timeframe with the DQL,&nbsp;particularly when searching for information in the Logs.

Here are some examples to get around current limitations :

- For -1d/d :

```markup
fetch logs,from:toTimestamp("T00:00:00")-1d

```

- For -0d/d :

```markup
fetch logs,from:toTimestamp("T00:00:00")

```

- For GMT+2 :

```markup
fetch logs,from:toTimestamp("T00:00:00+2")

```

I hope this TIP can be useful to as many people as possible 🙂  
Please let me know your comments.

---

<div class="post-metadata">

**Author:** ![radek\_jasinski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radek_jasinski/32/10432_2.png) [@radek\_jasinski](https://community.dynatrace.com/u/radek_jasinski)\
**Post date:** [November 16, 2023, 1:37pm UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655/2 "2023-11-16T13:37:37Z")

</div>

Great​😊 Thank you it’s a very useful

---

<div class="post-metadata">

**Author:** ![g\_pmu](https://avatars.discourse-cdn.com/v4/letter/g/ccd318/32.png) [@g\_pmu](https://community.dynatrace.com/u/g_pmu)\
**Post date:** [November 27, 2023, 9:16am UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655/3 "2023-11-27T09:16:10Z")

</div>

Great !

---

<div class="post-metadata">

**Author:** ![36Krazyfists](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/36krazyfists/32/37434_2.png) [@36Krazyfists](https://community.dynatrace.com/u/36Krazyfists)\
**Post date:** [December 12, 2023, 6:24pm UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655/4 "2023-12-12T18:24:07Z")

</div>

What is this “toTimestamp” function?&nbsp; I tried searching for it and, while I see it used in examples in their documentation, I don’t see any explanation of what the function actually is, and my Google searches aren’t producing results.

\ ***EDIT** \* Ahh, found it.&nbsp; It’s in their Conversion and Casting Functions section of their docs instead of in their Time functions section.&nbsp; They should maybe cross-reference those though, just to make finding it easier.

---

<div class="post-metadata">

**Author:** ![Christophe\_N](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@Christophe\_N](https://community.dynatrace.com/u/Christophe_N)\
**Post date:** [March 4, 2024, 12:56pm UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655/5 "2024-03-04T12:56:19Z")

</div>

Hi all ,

Thanks for the tip here&nbsp;😀  
Do you have any other tip if we want to go through relative timeframe?

like if I want relative timings (like “now-1h/h to now-0h/h”) or “from: now-1M/M to :now-0M/M” , I have the message “ **The parameter `from` has to be constant** ”  
I have not found any tips to do so.

Temp solution I have found is to query larger data and then filter afterwards :

```markup
|filter getHour(timestamp) >= (getHour(now())-1) and getHour(timestamp) < getHour(now())

```

Is it possible to do it directly from timeframe filter ?

Best regards,

Christophe

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [October 12, 2024, 1:23pm UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655/6 "2024-10-12T13:23:11Z")

</div>

Thanks for sharing useful tip.

---

<div class="post-metadata">

**Author:** ![Christophe\_N](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@Christophe\_N](https://community.dynatrace.com/u/Christophe_N)\
**Post date:** [December 11, 2024, 5:46pm UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655/7 "2024-12-11T17:46:23Z")

</div>

Hi all,  
additional tip , for those who wants to use dashboard timeframe in one calculation

For example, if you want to use the timeframe of one&nbsp;dashboard in one tile , here is a tip you can use :

```markup
| lookup [
data record(timestamp=now())
| makeTimeseries sum(1)
| fieldsAdd fk=1, timeframe=timeframe[end]-timeframe[start]-interval
], lookupField:fk, sourceField:fk, fields:{timeframe}

```

For example,&nbsp; you want to have Outage duration&nbsp; calculation from Davis Events

```markup
fetch events
| filter event.kind == "DAVIS_EVENT"

//you can add any filter here 
| fieldsAdd duration=event.end-event.start| filter isNotNull(duration)
| fields event.start,event.end,duration,arrayLast(entity_tags),Tags=arrayFlatten(entity_tags) 
| summarize `Outage Duration`= sum(duration), by:{ Tags}
| fieldsAdd fk=1
| lookup [
data record(timestamp=now())
| makeTimeseries sum(1)
| fieldsAdd fk=1, timeframe=timeframe[end]-timeframe[start]-interval
], lookupField:fk, sourceField:fk, fields:{timeframe}
| fieldsadd `Availability : 100%-duration outage`= if(100*(1-(`Outage Duration`/timeframe))>0,(100*(1-(`Outage Duration`/timeframe))),else:100) , `Outage Duration`=if(isNull(`Outage Duration`),0,else:`Outage Duration`)
| fields Tags,`Availability : 100%-duration outage`,`Outage Duration`

```

Kudo to the support team to have found this while I got exotic request 🙂

Christophe

---

<div class="post-metadata">

**Author:** ![Peter\_Jelitsch1](https://avatars.discourse-cdn.com/v4/letter/p/b5e925/32.png) [@Peter\_Jelitsch1](https://community.dynatrace.com/u/Peter_Jelitsch1)\
**Post date:** [April 16, 2025, 10:08am UTC](https://community.dynatrace.com/t/tips-dql-timeframe-selection/42655/8 "2025-04-16T10:08:03Z")

</div>

Thanks, very helpful! A small **additional** hint when interested in **UTC**. Add the **“Z”** to your timestamp format. Example:

```markup
fetch events, from:toTimestamp("T00:00:00Z")-1d, to: toTimestamp("T00:00:00Z")
| summarize by: {}, sum=count()

```

gives use the count of events for yesterday, measured in UTC.

Edit: “T00:00:00Z” appears to be just a shortcut for “T00:00:00+0”

Cheers, PJ.
