T-SQL calculating average time

前端 未结 4 1517
走了就别回头了
走了就别回头了 2021-01-03 23:57

I have a problem with calculating average time. This is the case: i have multiple rows, in each row there is data in time format so I need to calculate an average time of al

4条回答
  •  甜味超标
    2021-01-04 00:00

    This may be useful in this and similar scenarios.

    Below will convert the date/time to a number of minutes since midnight. In other words time expressed as an integer. You can do an average on that and then convert back to time.

    declare @dt datetime = GETDATE();
    select DATEDIFF(minute, dateadd(dd, datediff(dd, 0, @dt), 0), @dt);
    --DATEDIFF(minute, [date without time i.e. midnight], [date/time of interest])
    

提交回复
热议问题