-2

I want to calculate the time spent by user on our system. In logs table we track currently login time but we don't have logout time logged currently. So to find out time spent by user in a session I want to find out difference between two login events

Example

For example user has logged in multiple times on 2022-02-16 so I have to calculate the time difference between two login events. How we can achieve in that SQL Server? I have to do this inside a view, so can not use any temp tables or SP

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • Please avoid posting [images](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) of data, sample data should be *consumable text* in your question, ideally as *create* and *insert* statements, or alternatively a [DB<>Fiddle](https://dbfiddle.uk/). See the [question guide](https://stackoverflow.com/help/how-to-ask). – Stu Feb 19 '22 at 10:07

1 Answers1

0

You want the Datediff(minutes, time1, time2)

Instead of minutes use the units you want to measure in.

Mike Wodarczyk
  • 1,247
  • 13
  • 18