Alan
Alan

Reputation: 177

Average between two columns in mysql that are date not timestamp

Alright so here it is. I need to figure out the average amount of days between two columns.

Column 1 is recieved_date and column 2 is fix_date

Just want to know how to take the two dates find the difference in days, do that for every row and pop out a number stating the average amount of days it takes to fix something.

Tried to find it online but every time I find something like it, they have two specific dates. I need the entire columns averaged.

Upvotes: 0

Views: 1211

Answers (2)

Daniel Zakrisson
Daniel Zakrisson

Reputation: 158

You can use the TIMESTAMPDIFF function both for dates and datetime.

See Mysql average time between visits

Upvotes: 1

user645280
user645280

Reputation:

Add a group by and some other columns to this and it should do the trick:

select 
  avg(fix_period)
from
(
select
  datediff(fix_date, received_date) as fix_period
  from some_table
) as a
;

Upvotes: 0

Related Questions