tags:

views:

294

answers:

1

Is there a function to find average time difference in the standard time format in my sql.

+1  A: 

You can use timestampdiff to find the difference between two times.

I'm not sure what you mean by "average," though. Average across the table? Average across a row?

If it's the table or a subset of rows:

select
    avg(timestampdiff(SECOND, startTimestamp, endTimestamp)) as avgdiff
from
    table

The avg function works like any other aggregate function, and will respond to group by. For example:

select
    col1,
    avg(timestampdiff(SECOND, startTimestamp, endTimestamp)) as avgdiff
from
    table
group by col1

That will give you the average differences for each distinct value of col1.

Hopefully this gets you pointed in the right direction!

Eric
Thanks for response EricTIMEDIFF also gives me time difference. But want to find out the average time difference
rupa
@rupa: So not the averages I posted, then?
Eric