Reputation: 37
I want to output the time in and time out from this database.
So i want to get the first data and last data in date 2017-06-13 and 2017-06-15. How can i do that using Laravel 5.3?
Upvotes: 0
Views: 195
Reputation: 866
May be this will work for you:
DB::table('emp')
->select(DB::raw("MIN(`time`) AS `time_in`, MAX(`time`) AS `time_out`"))
->where('date', '2017-06-13')
->get();
Output:
{
time_in: "19:38:33",
time_out: "22:14:10"
}
Upvotes: 1
Reputation: 9307
Try Below Code :
$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();
Upvotes: 0
Reputation:
You can order your table by the date and time columns and then use Eloquent to take ->first() and ->last() using those methods.
$collection = BiometricsAttendance::where('emp_id', $emp)->whereBetween('date', [$start, $end])->groupBy('date')->orderBy('time', 'asc');
$timein = $collection->first();
$timeout = $collection->last();
Upvotes: 0