Soul Coder
Soul Coder

Reputation: 804

How to get only the current date and the previous dates in laravel?

I am trying to get only the current dates and the previous dates.Here is how i tried

$jobseekers = Calllog::orderBy('calllogs.created_at','DESC')
              ->get()->where('call_back_date', '<=', Carbon::today()->toDateString());

This show only the previous dates, i want to get both.If i remove "<", it shows only the current date.Help me out please.

Upvotes: 1

Views: 2650

Answers (3)

Umang Patel
Umang Patel

Reputation: 133

use below eloquent query

    $jobseekers = Calllog::whereDate('call_back_date','<=',Carbon::today)->get()

Upvotes: 1

prolific
prolific

Reputation: 775

$jobseekers = Calllog::orderBy('calllogs.created_at','DESC')->where('call_back_date', '<=', Carbon::now())->get();

Using now() instead of today(). Unlike today(), now() returns complete datetime at the moment.

Also notice that i moved where condition before get() to prevent fetching extra data from database.

Upvotes: 0

shukshin.ivan
shukshin.ivan

Reputation: 11340

Use tomorrow and < condition

$jobseekers = Calllog::orderBy('calllogs.created_at','DESC')
    ->get()->where('call_back_date', '<', Carbon::tomorrow()->toDateString());

Upvotes: 1

Related Questions