Question

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?

Was it helpful?

Solution

==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."

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top