Reputation: 915
I'm receiving the following error in Laravel 5.2
The following is the query :
$ansrow = DB::table('answers')
->where('user_id', $u_id)
->whereBetween('created_at', [
now()->format('Y-m-d H:00:00'),
now()->addHours(1)->format('Y-m-d H:00:00')
])
->first();
I receive the following error :
Call to undefined function App\Http\Controllers\now()
Upvotes: 2
Views: 3005
Reputation: 9171
You should use Carbon
, e.g.:
$ansrow = DB::table('answers')
->where('user_id', $u_id)
->whereBetween('created_at', [
\Carbon\Carbon::now()->format('Y-m-d H:00:00'),
\Carbon\Carbon::now()->addHours(1)->format('Y-m-d H:00:00')
])
->first();
And don't forget to assign the correct value to the 'timezone'
key in config/app.php
or you'll get UTC
datetime (UTC
is the default).
Upvotes: 4