# User session Query (Last 15 minutes)

**URL:** <https://community.dynatrace.com/t/user-session-query-last-15-minutes/31147>\
**Category:** Real User Monitoring\
**Tags:** usql, user-sessions\
**Created:** [April 15, 2021, 10:50am UTC](https://community.dynatrace.com/t/user-session-query-last-15-minutes/31147 "2021-04-15T10:50:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![service\_apms](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@service\_apms](https://community.dynatrace.com/u/service_apms)\
**Post date:** [April 15, 2021, 10:50am UTC](https://community.dynatrace.com/t/user-session-query-last-15-minutes/31147/1 "2021-04-15T10:50:10Z")

</div>

Hello,

Iam trying to force a query to give me the results of the last 15 minutes only.

As there is no “Last X” parameter in the USQL language i was wondering if there is another way.

FYI : It must always give me the last 15 minutes no matter when i execute it so i can’t actually specify a timeframe.

Example :

SELECT AVG(duration)  
FROM useraction  
WHERE useraction.application=‘XXXX’  
and useraction.name = 'YYYYYY’Thank you

---

<div class="post-metadata">

**Author:** ![pahofmann](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pahofmann/32/17076_2.png) [@pahofmann](https://community.dynatrace.com/u/pahofmann)\
**Post date:** [April 15, 2021, 10:57am UTC](https://community.dynatrace.com/t/user-session-query-last-15-minutes/31147/2 "2021-04-15T10:57:11Z")

</div>

Just set the time frame to 15 minutes. If you pin it to a dashboard you can select a custom timeframe of&nbsp; **-15m** for the USQL dashlet.

This won’t get you the result you want probably though. USQL only querries completed sessions and not live sessions.

---

<div class="post-metadata">

**Author:** ![service\_apms](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@service\_apms](https://community.dynatrace.com/u/service_apms)\
**Post date:** [April 15, 2021, 11:01am UTC](https://community.dynatrace.com/t/user-session-query-last-15-minutes/31147/3 "2021-04-15T11:01:25Z")

</div>

If it were a Dashboard it would be easier.

I actually wanna extract the JSON file via API and publish the results on another website.

So the custom Dynatrace timeframe won’t really help here. i was looking for something to add to the Query actually…

---

<div class="post-metadata">

**Author:** ![pahofmann](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pahofmann/32/17076_2.png) [@pahofmann](https://community.dynatrace.com/u/pahofmann)\
**Post date:** [April 15, 2021, 11:06am UTC](https://community.dynatrace.com/t/user-session-query-last-15-minutes/31147/4 "2021-04-15T11:06:51Z")

</div>

If it’s the API you have to set the time frame via&nbsp; **startTimestamp** and&nbsp; **endTimestamp,** &nbsp;there is no relative option unfortunately.&nbsp;It would be a good RFE to add a&nbsp; **relativeTime** field like for other API endpoints.

It would still contain only completed sessoins though.

---

<div class="post-metadata">

**Author:** ![pahofmann](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pahofmann/32/17076_2.png) [@pahofmann](https://community.dynatrace.com/u/pahofmann)\
**Post date:** [April 15, 2021, 11:25am UTC](https://community.dynatrace.com/t/user-session-query-last-15-minutes/31147/5 "2021-04-15T11:25:05Z")

</div>

Actually found a solution to do it inside the query. You can use the variable&nbsp; **$NOW** &nbsp;in the query to filter for an&nbsp; **endTime**. You can subtract an amount in&nbsp;milliseconds from it.

An example to get the end date of all sessions that ended in the last 15 minutes would be:

**SELECT endTime FROM usersession WHERE endTime \> $NOW-900000 order by endTime desc**

With **WHERE endTime \> $NOW-900000** &nbsp;you can filter your quert for all sessions that ended in the last 15min.

You could also use it to filter for user actions in the last 15 min, depending on what&nbsp; your query looks like.

---

<div class="post-metadata">

**Author:** ![service\_apms](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@service\_apms](https://community.dynatrace.com/u/service_apms)\
**Post date:** [April 15, 2021, 2:43pm UTC](https://community.dynatrace.com/t/user-session-query-last-15-minutes/31147/6 "2021-04-15T14:43:04Z")

</div>

That was helpful. thanks a lot !
