How to select data where today is between “from_date” and “to_date” columns

Here is sample query:

In repository,

public function getDataWhereTodayIsBetweenFromAndTo()
{
//get current date to check between from_date and to_date
//you will need to import Carbon
$today = Carbon::today()->toDateString();
$objs = DB::table(‘table_name’)
->select(DB::raw(‘id, max(amount) as maximum_amount’))
->whereNull(‘deleted_at’)
->where(‘from_date’,'<=’, $today)
->where(‘to_date’,’>=’, $today)
->groupBy(‘category_id’)->get();
return $objs;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s