Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date Difference in MySQL in Minutes

Tags:

mysql

heidisql

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.

like image 402
Alankar Avatar asked Dec 15 '25 01:12

Alankar


1 Answers

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.

like image 194
DeepBlue Avatar answered Dec 16 '25 19:12

DeepBlue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!