# Add a variable to the “from:" and "to:” section of a DQL query

**URL:** <https://community.dynatrace.com/t/add-a-variable-to-the-from-and-to-section-of-a-dql-query/50834>\
**Category:** DQL\
**Tags:** dql, logs\
**Created:** [March 21, 2025, 2:10pm UTC](https://community.dynatrace.com/t/add-a-variable-to-the-from-and-to-section-of-a-dql-query/50834 "2025-03-21T14:10:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwinkler109](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@cwinkler109](https://community.dynatrace.com/u/cwinkler109)\
**Post date:** [March 21, 2025, 2:10pm UTC](https://community.dynatrace.com/t/add-a-variable-to-the-from-and-to-section-of-a-dql-query/50834/1 "2025-03-21T14:10:03Z")

</div>

Is it possible to add a variable to the “from:" and&nbsp; "to:” section of a DQL query that is fetching logs?

**Background:** I have a dashboard that surfaces info from logs from a specific time of the day each morning. I want to be able to select a value in a dashboard variable that represents today, yesterday, 2 days ago, 3 days ago, etc. and have the dashboard show data for that specific time period of the chosen day.

The following DQL examples work correctly. I’d like to have a dashboard variable that changes the day being specified in the To and From sections.

**Today:**

- fetch logs, from: bin(now(), 1d)+ 5h + 50m, to: bin(now(), 1d) + 6h + 30m

**Yesterday** :

- fetch logs, from: bin(now()-1d, 1d)+ 5h + 50m, to: bin(now()-1d, 1d) + 6h + 30m

**Two Days Ago:**

- fetch logs, from: bin(now()-2d, 1d)+ 5h + 50m, to: bin(now()-2d, 1d) + 6h + 30m

Is this possible? What would the DQL look like?

---

<div class="post-metadata">

**Author:** ![AustinSabel](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/austinsabel/32/19170_2.png) [@AustinSabel](https://community.dynatrace.com/u/AustinSabel)\
**Post date:** [April 2, 2025, 3:34pm UTC](https://community.dynatrace.com/t/add-a-variable-to-the-from-and-to-section-of-a-dql-query/50834/2 "2025-04-02T15:34:51Z")

</div>

[@cwinkler109](https://community.dynatrace.com/user/69707)&nbsp;you can accomplish this using a list variable, for example:

 ![AustinSabel_2-1743605203094.png](https://global.discourse-cdn.com/dynatrace/original/2X/3/3ab011d690e83cccc143c144066a12e915e1be67.png)

Along with the following query:

```javascript
fetch logs, 
 from: duration(toLong(concat("-",$daysAgo)), unit:"d")@d+5h+50m, 
 to: duration(toLong(concat("-",$daysAgo)), unit:"d")@d+6h+30m
| summarize min(timestamp), max(timestamp)

```

As a side note, just so I understand it, are you looking to create a dashboard that shows logs for a given day between 5:50am and 6:30am local time? If so, you may get some inconsistent responses using bin() format based on the timezone.

I’ve attached a copy of an example dashboard using this functionality and showing some differences between bin() and&nbsp;@d.  
[Timeframe Variable Test.json.zip](https://community.dynatrace.com/uploads/short-url/qE1Im0ceIVc0ql5t7VmZZ9efZ8j.zip) (1.96 KB)

---

<div class="post-metadata">

**Author:** ![cwinkler109](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@cwinkler109](https://community.dynatrace.com/u/cwinkler109)\
**Post date:** [April 3, 2025, 8:58pm UTC](https://community.dynatrace.com/t/add-a-variable-to-the-from-and-to-section-of-a-dql-query/50834/3 "2025-04-03T20:58:48Z")

</div>

Perfect. AustinSable, you are a DQL hero, and saved my dashboard. Thank you!!!

---

<div class="post-metadata">

**Author:** ![AustinSabel](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/austinsabel/32/19170_2.png) [@AustinSabel](https://community.dynatrace.com/u/AustinSabel)\
**Post date:** [April 9, 2025, 2:30pm UTC](https://community.dynatrace.com/t/add-a-variable-to-the-from-and-to-section-of-a-dql-query/50834/4 "2025-04-09T14:30:18Z")

</div>

Glad I could help!
