Menu
PHP BABA LOGO
  • Home
  • Interview Questions
    • PHP String Interview Question
    • PHP Array Interview Qutions
    • jQuery Interview Quetions
    • PHP Interviwe Question on php.ini file
    • htaccess File Interview Quetions
  • About
PHP BABA LOGO

MySQL booking date Query Problem between some date

Posted on June 22, 2017May 18, 2022

Question : When we have booking date (start date to end date) in db booking table and need to search from “from date” to ” to date” by search box for available seats.

booking table :

id name start_date end_date
1 a 23-06-2017 29-06-2017

here we need 4 condition to check to do not get in between those dates

Example : Search date can be those

1. 24-06-2017 to 25-06-2017

2. 22-06-2017 to 30-06-2017

3. 22-06-2017 to 24-06-2017

4. 25-06-2017 to 31-06-2017

Now Laravel Query :

$booking_arr = DB::table(‘booking’)
->whereRaw(“((booking.start_date <= ‘”.$start_date.”‘ AND booking.end_date > ‘”.$start_date.”‘) OR (booking.start_date < ‘”.$end_date.”‘ AND booking.end_date >= ‘”.$end_date.”‘) OR (booking.start_date >= ‘”.$start_date.”‘ AND booking.start_date <= ‘”.$end_date.”‘))”)
->where(‘booking.campsite_id’,$input[‘campsite_id’])
->whereIn(‘category_campsite_id’, $campsites_categories)
->get();

Categories

  • Docker
  • Git
  • Interview Questions
  • Laravel
  • Linux
  • php
  • Salesforce

Recent Posts

  • Batch Class in Salesforce
  • Platform Developer I Certification Maintenance (Winter ’24) Get Hands-on with Bind Variables in a SOQL Query
  • How to check Salesforce current release version
  • Salesforce Certification Coupons / Vouchers
  • Nested / Cascade query in SOQL

Recent Posts

  • Batch Class in Salesforce January 25, 2024
  • Platform Developer I Certification Maintenance (Winter ’24) Get Hands-on with Bind Variables in a SOQL Query December 19, 2023
  • How to check Salesforce current release version January 12, 2023
  • Salesforce Certification Coupons / Vouchers July 19, 2022
  • Nested / Cascade query in SOQL May 11, 2022
©2025 The Tech Paper | Powered by Abhinav Trivedi