-1

I am using this query to get all the dates between 2 dates:

$getDates="SELECT daily_rate_date FROM daily_rates  WHERE daily_rate_date BETWEEN '".$checkOut."' AND '".$departureDate."' AND daily_rate_reservation=$reservationId;";

The thing is that if for example $checkOut = 03-03-2021 and $departureDate = 07-03-2021, I get the dates:

04-03-2021
05-03-2021
06-03-2021

but i also need the $checkOut date too to be included (but not the $departureDate) :

03-03-2021 
04-03-2021
05-03-2021
06-03-2021

How can I accomplish that?

Nikos
  • 1
  • 2
  • `WHERE daily_rate_date >= '".$checkOut."' AND daily_rate_date < '".$departureDate."'` ? See also how to [Use prepared statements and parameterized queries](https://stackoverflow.com/a/60496/9193372) – Syscall Mar 02 '21 at 17:48
  • Almost duplicate (different language but basically the same), but I believe that this is the answer that you want. https://stackoverflow.com/a/43633362/498699 – Schleis Mar 02 '21 at 17:49

2 Answers2

0

then change your query to:

$getDates="SELECT daily_rate_date FROM daily_rates  
           WHERE daily_rate_date >= '".$checkOut."' 
           AND   daily_rate_date < '".$departureDate."' 
           AND   daily_rate_reservation=$reservationId;";
eshirvana
  • 23,227
  • 3
  • 22
  • 38
0

You could use >= and < operators instead of between for you use case.

$getDates="SELECT daily_rate_date FROM daily_rates  WHERE daily_rate_date >= '".$checkOut."' AND < '".$departureDate."' AND daily_rate_reservation=$reservationId;";
naghal
  • 537
  • 3
  • 19