Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top