Laravel - where less/greater than date syntax

We can also try this one. It works for me.

    $date = "2020-04-10";

    /* 
    Assumimng DB `login_date` datetime format is "Y-m-d H:i:s"
    */

    $from_date = $date.' 00:00:01';

    ->where('login_date', '>=', $from_date);

By adding Where Clause in the query, we can find the result having rows after the particular date.

Option-2:

$date = "2020-03-25";    // Format: date('Y-m-d);

$orders = DB::table('orders')
               ->select('*')
               ->whereDate('order_datetime', '<=', $date)
               ->get();

// Here, Table Field "order_datetime", type is "datetime" 
// Assuming DB `order_datetime` stores value format like: "Y-m-d H:i:s"

Use a Carbon instance:

$this->data['Tasks'] = \DB::table('tb_tasks')->where('Status', 'like', 'Open%')->whereDate('DeadLine', '>', Carbon::now())->count();

You can also use the now() helper

$this->data['Tasks'] = \DB::table('tb_tasks')->where('Status', 'like', 'Open%')->whereDate('DeadLine', '>', now())->count();

you can make use of whereDate like below:

$query->whereDate('DeadLine', '>', Carbon::now())->count();

Use DB::raw:

->where('datefield', '>', \DB::raw('NOW()'))

Tags:

Php

Laravel