简体   繁体   中英

How can we convert below normal query to Laravel DB or Elequent?

I am trying the get the records that are in between the start and end date based on the current date. I have normal SQL working query and now I am trying it to convert into eloquent query, but I am failing somewhere. Please help me for for this.

BASIC QUERY:

SELECT startDate, endDate FROM YourTable WHERE '2012-10-25' between startDate and endDate

What I had tried:

$q = RoundTable::select(['round_start_date','round_end_date'])->whereBetween('2019-10-25', ['round_start_date', 'round_end_date'])->get();

I got an error as

  Column not found: 1054 Unknown column '2019-10-25' in 'where clause' (SQL: select ` 
   round_start_date`, `round_end_date` from `round_table` where `2019-10-25` between round_start_date 
   and round_end_date`

Change query to:

$q = RoundTable::select(['round_start_date','round_end_date'])
->whereRaw('? between round_start_date and round_end_date', ['2019-10-25'])
->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM