Review the individual tables you are querying such as the Schedule Log, Session, or Work Queue table. Some tables have date columns in GMT time and some have the dates saved in the local server time (time on the database). Here are examples below of how I have evaluated time in my time zone (US Eastern Standard Time) where there is a need to convert the time and where there is not a need to convert the time. I have one database server for the environment, thus everything is in the same time zone.
Reviewing
Schedule Logs for terminations in the last 24 hours and no session was created (good to see if a Schedule terminated and may not have even created a Session) -- need to CONVERT the date time -- adjust GMT by 5 hours:
SELECT
[id]
,[schedulelogid]
,[entrytype]
,FORMAT(([entrytime] - (RIGHT(CONVERT(datetime,SYSDATETIME()) AT TIME ZONE 'US Eastern Standard Time', 5))), 'MM-dd-yyyy hh:mm:ss tt') AS [Entry Time]
,[taskid]
,[logsessionnumber]
,[terminationreason]
,[stacktrace]
FROM [BLUE_PRISM_PR].[dbo].[BPAScheduleLogEntry]
WHERE [terminationreason] IS NOT NULL
AND [logsessionnumber] IS NULL
AND DATEDIFF(hour,(BLUE_PRISM_PR.dbo.
BPAScheduleLogEntry.
entrytime -
(RIGHT(CONVERT(datetime,SYSDATETIME()) AT TIME ZONE 'US Eastern Standard Time', 5))), SYSDATETIME()) <= 24
ORDER BY [entrytime] DESC
Yet, if you are looking to see what Sessions failed in the last 24 hours (where the Schedule started a session or someone triggered a run from the Control Room manually), you
do not need to convert the time since it is presented in the local time zone:
SELECT
dbo.BPVSessionInfo.sessionnumber AS [Session ID],
dbo.BPVSessionInfo.processname AS [Process],
dbo.BPVSessionInfo.runningresourcename AS [Resource],
dbo.BPVSessionInfo.starterusername AS [User],
dbo.BPAStatus.description AS [Status],
FORMAT(dbo.BPVSessionInfo.startdatetime, 'MM-d-yyyy hh:mm tt') AS [Start Time],
FORMAT(dbo.BPVSessionInfo.enddatetime, 'MM-d-yyyy hh:mm tt') AS [End Time]
FROM dbo.BPVSessionInfo INNER JOIN dbo.BPAStatus ON dbo.BPVSessionInfo.statusid = dbo.BPAStatus.statusid
WHERE
dbo.BPVSessionInfo.statusid = 2
AND dbo.BPVSessionInfo.starterusername = '[Scheduler]'
AND DATEDIFF(hour, dbo.BPVSessionInfo.startdatetime, SYSDATETIME()) <= 24
------------------------------
Brenton Westwood
Systems Analyst
Southern Company
------------------------------