sql avg

I have a database table that has 2  columns. defined as datetime, length of 8.
the column/data looks like :

tir_start - 1/1/1900 2:38:52 PM
tir_end - 1/1/1900 2:39:37 PM

there are many rows per day..the day date is another column.

I need to determine the avg time between the start and end column for many rows.  

Who is Participating?
anillucky31Connect With a Mentor Commented:
SELECT AVG(DATEDIFF(s,tir_start,tir_end)) FROM  yourtable

this will give time difference in seconds and will average them.
TonyRebaConnect With a Mentor Commented:
First have calculated the date diff

DATEDIFF ( datepart , startdate , enddate )

Once you have that you can use the AVG function)
Avg (datediffcolumn)
Ephraim WangoyaConnect With a Mentor Commented:
select daycolumn, TotalMinutes / count(*) [Average time]
  select daycolumn, SUM(DATEDIFF(MINUTE, tir_start, tir_end)) as TotalMinutes
  from table1
) A
group by daycolumn

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.