Director 7.15.1000 : Custom Script and SQL query providing different results for same operation

Director 7.15.1000 : Custom Script and SQL query providing different results for same operation

book

Article ID: CTX235271

calendar_today

Updated On:

Description

User-added image
As seen below the session counts varies :
User-added image

Resolution

Make modification on below query, then you should be able to fetch complete data as per current date and time. 
select 
u1.UserName, 
a1.Name, 
CONVERT(datetime, SWITCHOFFSET(CONVERT(datetimeoffset, CONVERT(datetime,ap1.StartDate,121)), DATENAME(TzOffset, SYSDATETIMEOFFSET()))) as starttime, 
CONVERT(datetime, SWITCHOFFSET(CONVERT(datetimeoffset, CONVERT(datetime,ap1.EndDate,121)), DATENAME(TzOffset, SYSDATETIMEOFFSET()))) as endtime 
from 
[MonitorData].[SessionV1] as s1 join [MonitorData].[ApplicationInstance] 
as ap1 on (ap1.sessionkey=s1.sessionkey) 
join monitordata.[User] as u1 on (s1.userid=u1.id
join MonitorData.[application] as a1 on (ap1.ApplicationId=a1.Id
where s1.StartDate <= CONVERT (datetime, SYSDATETIMEoffset());

Problem Cause

• The SQL Query made us realize that Director is converting time adding 10 hours to final report.
• We can confirm that we save our data in UTC format to avoid conflicts between time zones.
• This is explained here https://docs.citrix.com/en-us/xenapp-and-xendesktop/current-release/director/data-retention.html

Issue/Introduction

This is for the issue where we get different result of a custom query generating user sessions and the applications launched. When executing SQL query for the same both provide different results causing data mismatch.