# Using Timeframe Selector as an input for a DQL query

**URL:** <https://community.dynatrace.com/t/using-timeframe-selector-as-an-input-for-a-dql-query/38758>\
**Category:** Developer Q&A Forum\
**Tags:** strato, coding-assistance\
**Created:** [March 9, 2023, 8:30am UTC](https://community.dynatrace.com/t/using-timeframe-selector-as-an-input-for-a-dql-query/38758 "2023-03-09T08:30:31Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![3ene](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/3ene/32/33646_2.png) [@3ene](https://community.dynatrace.com/u/3ene)\
**Post date:** [March 10, 2023, 3:02pm UTC](https://community.dynatrace.com/t/using-timeframe-selector-as-an-input-for-a-dql-query/38758/7 "2023-03-10T15:02:55Z")

</div>

There were a couple more bumps in the road, so I want to share my final solution to my problem here. Please note that for my app, I needed to initialize the values of the Timeframe and TimeframeDetail variables upon opening the app, which makes this a little more difficult. I do it with following 2 lines:

```auto
const [timeframe, setTimeframe] = React.useState<Timeframe>({from: 'now-7d',to: 'now'});
const [timeframeDetails, setTimeframeDetails] = React.useState<TimeframeDetails>({from: parseTime('now-7d')!, to:parseTime('now')!});

```

Parsing it into DQL works like this for me:

```auto
const queryBase: string = 'fetch events, from: '+JSON.stringify(timeframeDetails?.from.date)+', to:'+JSON.stringify(timeframeDetails?.to.date)

```

This results in following DQL:

```auto
fetch events, from: "2023-03-03T15:01:18.390Z", to:"2023-03-10T15:01:18.390Z" [...]

```

Thanks, Stefan for helping me figure this out!

---

_[View the full topic](https://community.dynatrace.com/t/using-timeframe-selector-as-an-input-for-a-dql-query/38758)._
