Menu
The Tech Paper
  • 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
The Tech Paper

MySQL booking date Query Problem between some date

Posted on June 22, 2017July 11, 2020

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();

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

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

Recent Posts

  • Ubuntu 20.04 Bluetooth not working [Resolved]
  • Git Log Commands
  • Create a swap memory in Linux
  • Hide protected files in Laravel
  • Make a bootable pendrive in Linux

Archives

  • January 2021
  • December 2020
  • September 2020
  • July 2020
  • January 2020
  • July 2019
  • August 2018
  • June 2018
  • April 2018
  • September 2017
  • June 2017
  • May 2017

Recent Posts

  • Ubuntu 20.04 Bluetooth not working [Resolved] January 22, 2021
  • Git Log Commands January 22, 2021
  • Create a swap memory in Linux December 2, 2020
  • Hide protected files in Laravel September 21, 2020
  • Make a bootable pendrive in Linux September 10, 2020

Contact Us

©2021 The Tech Paper | Powered by SuperbThemes & WordPress