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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With