• if you want the date in the results for the CLOCK_IN and CLOCK_OUT columns then maybe you don't want to cast them to TIME datatype like I did in the Prep query. Otherwise, you'd have to add columns like this:

    WITH Prep AS

    (SELECT ci.person_num, ci.full_name, ci.event_name, CAST(DATEADD(hour,1,dbo.UtcToLocal(ci.creation_date)) AS DATE) AS event_date,

    CAST(dbo.UtcToLocal(ci.creation_date) AS date) AS in_date, CAST(dbo.UtcToLocal(ci.creation_date) AS time) AS in_time,

    CAST(dbo.UtcToLocal(co.creation_date) AS date) AS out_date, CAST(dbo.UtcToLocal(co.creation_date) AS time) AS out_time,

    DATEDIFF(minute, ci.creation_date, co.creation_date) AS minutes

    FROM TEST ci

    OUTER APPLY (SELECT TOP 1 creation_date FROM TEST t WHERE t.person_num = ci.person_num AND t.creation_date >= ci.creation_date AND t.event_name = 'CLOCK_OUT' ORDER BY t.creation_date) co

    WHERE ci.event_name = 'CLOCK_IN'

    AND ci.person_num = 20345),

    and include the new in_date, out_date columns in the CalcPart query and the final results query.