Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update time to NOW()?

I want to set a date field to NOW() if it's outdated. Here is the query I'm trying to run without success:

Quiz::('date', '<', DB::raw('NOW()'))->update(['date' => DB::raw('NOW()')])

How do I fix it?

P.S
I don't want to deal with Carbon, if possible, to avoid the server/DB time difference issues.

like image 322
Alex Lomia Avatar asked Jun 02 '16 22:06

Alex Lomia


1 Answers

Try something like:

DB::table('quizzes')->where(DB::raw('date < NOW()'))->update(['date' => DB::raw('NOW()')]);
like image 122
Denis Mysenko Avatar answered Sep 23 '22 19:09

Denis Mysenko