Below table shows the checkin & checkout time of employee
Emp_id report_date report_time
11 2014-12-01 08:02:31
21 2014-12-01 08:13:04
11 2014-12-01 18:03:41
21 2014-12-01 16:36:02
Below table shows the checkin & checkout time of employee
Emp_id report_date report_time
11 2014-12-01 08:02:31
21 2014-12-01 08:13:04
11 2014-12-01 18:03:41
21 2014-12-01 16:36:02
You need to convert time values to seconds check this post:
MySQL: how to get the difference between two timestamps in seconds
I'll share with you a working code but it is important that you understand what is going on with it.
SELECT `Emp_id`, `report_date`, min(`report_time`) AS chekin,
max(`report_time`) AS chekout,
( (TIME_TO_SEC(TIMEDIFF(max(`report_time`), min(`report_time`))) / 60) / 60) difference
FROM `your_table` WHERE 1 GROUP BY `Emp_id`, `report_date`
First you group by employee id and report date, that way you get one row for each id on distinct date. Then you select the minimal time for employee on that given date, and also the max time. Then you get the time difference in seconds, divide it by 60 so you get it in minutes, and then divide it again by 60 so you get it in hours.