Help with Time Duration

  • I have a table of user activities look like below:

    NameLoginLogout
    A7:4514:20
    A14:3817:55
    B10:2515:10
    B15:2017:22
    B17:2518:00

    How do I get a report with expected output as:

    NameDuration
    A9:52
    B7:22

    Duration is total of time a user spent between each login and logout.  Thanks. 

    p.s the login and logout time are converted from a date time column.  I still have the time in original format.

  • select [name],sum(datediff(n,logout,login)) /*total amount of minutes*/

    from mytable

    group by [name]

    order by [name]

    You can format the amount of minutes in your report or with a userdefined function.

  • thanks for your reply.  I figured it out, similar with yours but mine is longer.

     

  • It's even more simple than you can imagine:

    Logout - Login

    If you need it for presentation purposes:

    convert(varchar(8), Logout - Login, 108)

     

    _____________
    Code for TallyGenerator

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply