SQL - Condition with Between

-1

I have a form where the user can search for a date range, so far so good. If it searches only for a date, how can I do this directly in sql or even in php?!

Any suggestions?

    
asked by anonymous 28.07.2018 / 15:02

1 answer

3

Simply put:

$data2 = empty($data2) ? $data1 : $data2;
$sql = "SELECT ... BETWEEN $data1 AND $data2;";

If the second date is done, it receives the value of the first date if not the value itself, you can use other values if the second date is empty, for example, "NOW()"

    
28.07.2018 / 15:14