简体   繁体   中英

UNIX Timestamp Time Difference Average MYSQL

I am currently working on a ticket system in which I would like to work out the average amount of time it is taking staff to respond to tickets.

I have 2 columns that hold the UNIX timestamps: timestamp (when ticket was submitted) and endstamp (when ticket was closed)

SELECT AVG(TIMEDIFF(endstamp,timestamp)) AS timetaken FROM `tickets`

I'm not really sure what I am doing wrong.

Any help would be much appreciated!

A UNIX timestamp is just a representation of a point in time as a number of seconds, so basically an integer value. On the other hand, date function timestampdiff() operates on 3 parameters: a unit, and two values (or expressions) of datetime datatype (or the-like). Your query should actually raise a syntax error, since what you are giving as first argument is not a legal unit.

If you want the difference in seconds between two UNIX timestamps, just substract them, so:

SELECT AVG(endstamp - timestamp) AS timetaken FROM `tickets`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM