i have a very simple SQL which driving me crazy. I am working with Car Rental - so there is a FromDate and a ToDate (booked cars)
My MySQL loos like this:
id | FromDate | ToDate
-----------------------
24 | 01.10.2020 | 31.10.2020
so if a user choose a Date in between this, he should get a message that the car is already booked. What i have tried so far:
SELECT id FROM booked_cars WHERE ($fromdate BETWEEN date(FromDate) AND date(ToDate)) AND vhId = $vhid
SELECT id FROM booked_cars WHERE ($fromdate BETWEEN date(FromDate) AND date(ToDate) AND $todate BETWEEN date(FromDate) AND date(ToDate)) AND vhId = $vhid
SELECT id FROM booked_cars WHERE (date(FromDate) BETWEEN $fromdate AND $todate) AND vhId = $vhid
my $fromdate, $todate and $vhid comes with a POST-Form. The Values are
$fromdate = 03.10.2020
$todate = 07.10.2020
$vhid = 24
no matter what i try, my $statement->rowCount() is alway zero.
i am using PDO with prepared Statements. i just wrote it without for better reading.
$statement = $pdo->prepare("SELECT id FROM booked_cars WHERE (:fromdate BETWEEN date(FromDate) AND date(ToDate)) AND vhId = :vhid");
$statement->execute(array('fromdate' => $fromdate, 'vhid' => $vhid));
echo $statement->rowCount(); // Alway 0 with BETWEEN (when i select just the vhid, i got the result)