Reputation: 378
I'm trying to do a search.
And there is an input startDate and another one finalDate.
but the person might not type a start or final date or neither...
im trying to use:
(data BETWEEN ".$startDate." AND ".$finalDate.")
Leaving it blank it's not working, unless i put a start and final dates.
I wanted that even if the person doesn't type the dates, it keeps searching for the rest.
is that possible?
Upvotes: 0
Views: 87
Reputation: 101
==edited as per request==
put it before sql query:
if(empty($finalDate))
$where = "(data >= ".$startDate.")";
else if(empty($startDate))
$where = "(data <= ".$finaltDate.")";
else
$where = "(data BETWEEN ".$startDate." AND ".$finalDate.")";
and change
(data BETWEEN ".$startDate." AND ".$finalDate.")
with
".$where."
Upvotes: 1
Reputation: 7679
Yes you can probably do something like this.
CASE WHEN StartDate IS NOT NULL
AND EndDate IS NOT NULL
THEN Date
BETWEEN StartDate AND EndDate;
This is just an illustration of how it can be done , give it a shot
Upvotes: 0