i have basic table captures sign in , out of member of staff.
i using laravel back-end , im struggling how total number of hours on site.
id | in_time | out_time | in_date | out_date 1 | 21:22:49 | 21:46:05 | 2016-01-28 | 2016-01-28 2 | 08:12:12 | 14:12:01 | 2016-01-28 | 2016-01-28
see query far
$date1 = '2015-01-28'; $date2 = '2015-01-28'; $attendancehours = db::table('staff_attendances')->wherebetween('in_date', array($date1, $date2))->where('id', $sid) ->get();
how output total hours on site daterange?
two ways go
use carbon see documentation on difference
plenty of examples of on website
assuming using mysql use
timestampdiff
select timestampdiff(hour,'2003-02-01','2003-05-01 12:05:55');
you can raw query in laravel like
$attendancehours = db::select( db::raw('timestampdiff(hour,concat(in_date," ",in_time),concat(out_date," ",out_time)'))-> table('staff_attendances')-> wherebetween('in_date', array($date1, $date2))-> where('id', $sid) ->get();
warning: haven't tested above should work.
Comments
Post a Comment