Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - where less/greater than date syntax

Tags:

php

laravel

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(); 
like image 977
Selim Avatar asked Dec 16 '16 08:12

Selim


People also ask

How to compare date in Laravel query?

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.

How do I use whereBetween in Laravel?

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.

What is OMR in Laravel?

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.

What is DB :: unprepared in Laravel?

DB::unprepared - Option to return false on failure Upon a successful entry the method return true and all works as expected.


1 Answers

Use a Carbon instance:

$this->data['Tasks'] = \DB::table('tb_tasks')->where('Status', 'like', 'Open%')->whereDate('DeadLine', '>', Carbon::now())->count(); 
like image 190
jeanj Avatar answered Sep 21 '22 00:09

jeanj