3

I need to find the time difference in Hours for the following Dates in MySQL - Can i use Datediff functions?

2014-01-01 07:27:21 and 2014-02-01 11:29:00

I tried using DATEDIFF(MINUTE,'2014-01-01 07:27:21','2014-01-01 11:29:00') but apparently MySQL is giving an error.

Alankar
  • 197
  • 1
  • 3
  • 9

1 Answers1

6

Time difference in minutes:

SELECT ROUND(TIME_TO_SEC(timediff(date1,date2))/60) AS diff

Example:

SELECT ROUND(TIME_TO_SEC(timediff('2014-01-01 11:29:00','2014-01-01 07:27:21'))/60) AS diff

Result:

242

Time difference in hours:

SELECT ROUND(TIME_TO_SEC(timediff(date1,date2))/60/60) AS diff

if you need number of hours with fractions then remove ROUND.

DeepBlue
  • 684
  • 7
  • 23