sqlsql-server-2008datetime

I want Hours,Min, second difference from two datetime


I am developing Time management system for employees.

I want the duration how much duration employee come late , or he went early.

i have following structure.

**Attendace**  
AutoId --uniqueidentifier             
EMployeeId --uniqueidentifier
Date   --datetime
InTime -- varchar(50)
OutTime -- varchar(50)
ActualInTime--datetime
ActualOutTime--datetime

I want Late Coming Report ( i.e. who came late in morning after ActualInTime and how much duration in hh:mm:ss ) and also want early going(i.e who went early in the evening before ActualOutTime in duration in format hh:mm:ss )

So can you please help me..???


Solution

  • this code might help you...

    DECLARE @First datetime
    DECLARE @Second datetime
    SET @First = '04/02/2008 05:23:22'
    SET @Second = getdate()
    
    SELECT DATEDIFF(day,@First,@Second)*24 as TotalHours,
    DATEDIFF(day,@First,@Second)*24*60 as TotalMinutes,
    DATEDIFF(day,@First,@Second)*24*60*60 as TotalSeconds