This is not showing the correct count. What is the correct syntax ?
$this->data['Tasks'] = \DB::table('tb_tasks')->where('Status', 'like', 'Open%')->whereDate('DeadLine', '>', 'CURDATE()')->count();
Comparing date using raw query in laravel we will use DB::raw method to compare this. $users = DB::table('users') ->where('created_at', '2016-12-31') ->get(); //or $users = DB::table('users') ->where(\DB::raw('date("created_at")', '2021') ->get(); Comparing date in using operators like greater then equal to etc.
The whereBetween() method is a query builder chained alongside other Laravel query builders used to fetch data from the database. The whereBetween() method queries the database table to fetch rows of records from the database within a range of values.
Eloquent OMR(Object-relational Mapping) included with Laravel provides an attractive, simple Active record implementation for working with the database. Eloquent is an object that is representative of your database and tables, in other words, it acts as a controller between user and DBMS.
DB::unprepared - Option to return false on failure Upon a successful entry the method return true and all works as expected.
Use a Carbon instance:
$this->data['Tasks'] = \DB::table('tb_tasks')->where('Status', 'like', 'Open%')->whereDate('DeadLine', '>', Carbon::now())->count();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With