# USQL user session count difference when using global timeframe vs when using endTime/startTime in where clause.

**URL:** <https://community.dynatrace.com/t/usql-user-session-count-difference-when-using-global-timeframe-vs-when-using-endtime-starttime-in-where-clause/40353>\
**Category:** Troubleshooting\
**Tags:** real-user-monitoring-classic, user-actions, usql, user-sessions\
**Created:** [June 26, 2023, 10:10am UTC](https://community.dynatrace.com/t/usql-user-session-count-difference-when-using-global-timeframe-vs-when-using-endtime-starttime-in-where-clause/40353 "2023-06-26T10:10:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KiranSomanatti](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@KiranSomanatti](https://community.dynatrace.com/u/KiranSomanatti)\
**Post date:** [June 26, 2023, 10:10am UTC](https://community.dynatrace.com/t/usql-user-session-count-difference-when-using-global-timeframe-vs-when-using-endtime-starttime-in-where-clause/40353/1 "2023-06-26T10:10:16Z")

</div>

There is a difference between using the _ **startTime** _/_ **endTime** _&nbsp;in the&nbsp;WHERE clause and the_&nbsp; **Global time frame** in the USQL._  
&nbsp;  
USQL&nbsp;Global&nbsp;timeframe filter in WebUI will match all user sessions that were active between from and to time.&nbsp;  
That means it will match all user sessions that started and ended within the timeframe filter, all user sessions that started before the timeframe and ended within the timeframe, all user sessions that started within the timeframe and ended after the timeframe, and even all user sessions that started before the timeframe and ended after the timeframe  
&nbsp;  
and when you use the&nbsp;[_ **endTime** &nbsp;_](https://www.dynatrace.com/support/help/shortlink/api-usql-structure)where clause this will match only sessions that have the last useraction timestamp within this timeframe added in the query

or

when you use the&nbsp;[_ **startTime** &nbsp;_](https://www.dynatrace.com/support/help/shortlink/api-usql-structure)where clause this will match only sessions that have the first useraction timestamp within this time frame added&nbsp;in the query

![kiran_1-1687521354747.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/2/92b74a2e0da593cc8ea968ef472332f9fad19a14.png)

Example:  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;08:30&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 09:30  
timeframe filter &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|-----------------------------------------------|  
session 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|----------|  
session 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|-------------------|  
session 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |---------|  
session 4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|---------------------------------------------------------|

**With Endtime (in the uSQL query):**

_SELECT COUNT(\*) FROM usersession WHERE&nbsp; endTime \> 1687422600000 AND endTime \< 1687426200000&nbsp;_

_using the Where clause&nbsp; **endTime** &nbsp;count will be - 2 (session 1 and session 2)_

**Without Endtime (timeframe was set at the Global level 8:30 to 9:30 June 22)**

_SELECT COUNT(\*) FROM usersession&nbsp;_

using the&nbsp;_ **Global time frame** &nbsp;_count will be - 4 (all 4 sessions)

---

<div class="post-metadata">

**Author:** ![David\_Hauger](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/david_hauger/32/13595_2.png) [@David\_Hauger](https://community.dynatrace.com/u/David_Hauger)\
**Post date:** [June 28, 2023, 7:44am UTC](https://community.dynatrace.com/t/usql-user-session-count-difference-when-using-global-timeframe-vs-when-using-endtime-starttime-in-where-clause/40353/2 "2023-06-28T07:44:07Z")

</div>

**Side note** :  
If you want to have the global timeframe behaviour expressed as a filter, “all sessions active between 8:00 and 9:00” could be represented as “endTime after 8:00 and startTime before 9:00”  
The options are:

- all sessions that started in this timeframe:  
starttime within range (\> 8:30 and \< 9:30): sessions 2 and 3
- all sessions that ended in this timeframe:  
endtime within range (\> 8:30 and \< 9:30): sessions 1 and 2
- all sessions that started and ended in this timeframe:  
starttime \> 8:30 and endtime \< 9:30: session 2
- all sessions that were active in this timeframe:  
starttime \< 9:30 and endtime \> 8:30: sessions 1,2,3,4 (-\> global timeframe)

**Reason for picking that option** for the global timeframe: It includes most session; if you are interested in any other option, you can add the according filter.  
If we had used any other definition, e.g. session 4 would never appear, despite it was active during the whole timeframe and there would be no way to see “all active sessions”.

**Maybe related** :

When you use

_SELECT … from **usersession** WHERE \*\*useraction.\*\*startTime …_

it matches all sessions where AT LEAST ONE useraction matched your criteria; and you’ll get all matching usersessions.

_SELECT DISTINCT useraction.starttime from usersession WHERE useraction.startTime \> 1687422600000_

may still return you starttimes that are below the value.  
This feature is nice for co-occurrence analysis. If you are just interested in useractions, use

_SELECT … from **useraction** WHERE [useraction.]startTime …_
