Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only show hours in MYSQL DATEDIFF

I've been busy with this for hours, but I cant get it to work.

SQL  SELECT DATEDIFF(end_time, start_time) as `difference` FROM timeattendance WHERE timeattendance_id = '1484'  start_time =   2012-01-01   12:00:00 end_time =     2012-01-02   13:00:00 

The difference is 25 (hours). But the output I get is 1 (day).

How can I get the 25 hours as output?

like image 584
Mossawi Avatar asked Jul 20 '12 13:07

Mossawi


People also ask

How do I find the difference in hours in MySQL?

To calculate the difference between the timestamps in MySQL, use the TIMESTAMPDIFF(unit, start, end) function. The unit argument can be MICROSECOND , SECOND , MINUTE , HOUR , DAY , WEEK , MONTH , QUARTER , or YEAR .

How do I find the difference between two dates and time in MySQL?

Discussion: To count the difference between dates in MySQL, use the DATEDIFF(enddate, startdate) function. The difference between startdate and enddate is expressed in days. In this case, the enddate is arrival and the startdate is departure .

Does datediff working in MySQL?

The DATEDIFF function can be used in the following versions of MySQL: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1.

How does MySQL calculate elapsed time?

To compute the total elapsed time, use TIME_TO_SEC( ) to convert the values to seconds before summing them. : TIME_TO_SEC « Date Time « SQL / MySQL. To compute the total elapsed time, use TIME_TO_SEC( ) to convert the values to seconds before summing them.


1 Answers

What about using TIMESTAMPDIFF?

SELECT TIMESTAMPDIFF(HOUR, start_time, end_time)             as `difference` FROM timeattendance WHERE timeattendance_id = '1484' 
like image 107
FlyingMolga Avatar answered Sep 19 '22 04:09

FlyingMolga