-1

I am trying to select today's date based on if the date is in between two dates, check-in date, and check-out date.

Is there a way to do that using MySQL query?

My database is structured with saving only the check-in date and checkout date like this,

Text

And selecting the dates using the below code,

public function collection() {
    return Booking::select(
        'id',
        'place_id',
        'payer_name',
        'user_fullname',
        'user_email',
        'user_phone',
        'user_no_of_guest',
        'user_no_of_babies',
        'user_checkin',
        'user_checkout',
        'is_approved',
        'user_promo',
        'user_payment_type',
        'user_booking_tracking_id',
        Booking::raw('(created_at +  INTERVAL 2 HOUR) AS created_at'),
        'paid_ammount'
    )->where('user_checkin', $this->date)
    ->get();
}

Is there a way to select it using Laravel query? or should I create a function that selects a date that fits and then call it? I'm a bit new to Laravel, so I'm not really sure how to approach it.

2
  • Thank you for the response, however, this is not what I'm looking for. Thank you for your suggestion regardless. Commented Jun 15, 2021 at 9:30
  • It's exactly what you're looking for. :-( Commented Jun 15, 2021 at 10:24

1 Answer 1

1
 $date = Carbon::now();
 $result = Booking::whereRaw('"'.$date.'" between `user_checkin` and `user_checkout`')->get()->toArray();

use laravel whereRaw()

Hope fully it will help to you easily.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried this one, and it works, the only problem is its I need it to be inclusive, the date user_checkin is being selected, but the date where the user_checkout is not, any idea what could be causing that?
means you have only one date - user_checkin?
Thank you for the help, your solution worked. Just had to adjust a few params. Thanks again!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.