The sum of all SQL Server matter that exist,
and the space in which all SQL Server events
occur or could occur.
Welcome to SQL Server Universe.com Sign in | Join | Help
in
Home SS SLUG Forums Articles Photos Downloads

How to sum up date time columns

Last post 09-16-2008, 15:06 by lucki. 0 replies.
Sort Posts: Previous
  • How to sum up date time columns

     09-16-2008, 15:06

    • Joined on 10-17-2007
    • Posts 6
    • Points 0
    • Top 25 Contributor

    Hi,

    I have a little problem. I have 4 datetime  values.

     2008-01-04 11:33:05.000,

    2008-01-04 12:12:44.000,

    2008-01-04 12:22:43.000,

    2008-01-04 17:14:03.000

    All these are For the same date.I want to write a function to get the total time difference like this.

    2008-01-04 12:12:44.000   -    2008-01-04 11:33:05.000 = 27s

    2008-01-04 17:14:03.000  -     2008-01-04 12:22:43.000=  6:52

    Then to add them up 27+6.52= 7 hrs and 19 minutes.

    Can someone plz give me a coding to write this.

    This was the sp that i wrote earlier.This will return the employee in time and out time.But thats not the way i want it to be.I want the in between time slots also to get the total time and add them up.

    CREATE PROC [dbo].[sp_TotalAttendanceSummary](@EmployeeIdList nvarchar(MAX),@StartDate Datetime,@EndDate DateTime)

    AS

    create table #TotalAttendance(

    Date datetime,

    Employeename varchar(200),

    Intime datetime,

    Outtime datetime,

    Totaltime char(10))

     

    insert into #TotalAttendance(Date,Employeename,Intime,Outtime)

    Select distinct CONVERT(VARCHAR(10), MovementDateTime, 101) AS Date,

    Employee.EmployeeName,

    min(MovementDateTime),

    max(MovementDateTime)

    from MovementInformation

    INNER JOIN Employee ON (MovementInformation.EmployeeId = Employee.Id)

    where MovementDateTime between @StartDate and @EndDate

    and

    MovementInformation.EmployeeId in (select * from dbo.GetIds(@EmployeeIdList))

    group by CONVERT(VARCHAR(10), MovementDateTime, 101),EmployeeName

    update #TotalAttendance

    SET Totaltime =CONVERT(CHAR(8),(SELECT OutTime-InTime),8)

     

    Thanks.

    Lucki

View as RSS news feed in XML

(Best viewed with a resolution of more than 1024 * 768)

Powered by Community Server, by Telligent Systems