How to get time difference (in hours) between 2 dates

You must have a from clause in your select statement. Something like

Select date1 - date2 from dual

returns number of days between date1 and date2.

If you want number of hours:

Select (date1 - date2)*24 from dual;

(this is only for oracle)


From MySQL DATEDIFF docs:

Only the date parts of the values are used in the calculation.

You will want to look at TIMEDIFF

This will give you the number of hours in the difference in times (assuming your time_c fields are DATETIME or something similar)

SELECT HOUR(TIMEDIFF(  
  (SELECT max(u1.time_c) FROM users u),
  (SELECT max(u2.time_c) FROM users u2)
)) 

Tags:

Mysql

Sql

Oracle