colombo
colombo

Reputation: 520

DB update query in Laravel?

I'm trying to update the hours_worked column in daiy_attendance table using in_time and out_time in same table. in_time and out_time already stored in the table.

So I'm using timediff to get the difference. Query runs and execute correctly when I try it on the phpmyadmin sql format, but when I try to run it in the program it does not update the hours_worked column. It does not gives any errors.

$sql5 = "UPDATE daily_attendances SET hours_worked = TIMEDIFF(out_time,in_time) WHERE in_time != '' AND out_time != '' ";
$result2 = DB::statement(DB::raw($sql5));

Upvotes: 2

Views: 5643

Answers (1)

sumit
sumit

Reputation: 15464

try

DB::table('daily_attendances')
                ->whereRaw("in_time != '' AND out_time != ''")
                ->update(['hours_worked ' =>DB::raw('TIMEDIFF(out_time,in_time)')]);

OR JUST use db:statement

$sql5 = "UPDATE daily_attendances SET hours_worked = TIMEDIFF(out_time,in_time) WHERE in_time != '' AND out_time != '' ";
$result2 = DB::statement($sql5);

Upvotes: 4

Related Questions