SQL - Condition with Between

Asked

Viewed 499 times

-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 in a direct way in sql or even in php ?!

Any suggestions ?

  • 1

    The query is the same, but you need by the exact date of the record.

  • If you put the date in the points of the between, works!

  • An example of the table you are working on is missing. And the problem makes no sense to tag phpmyadmin

1 answer

3


Simply:

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

If the second date is done you receive 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()"

  • In the bank I’m using the timestamp, using this way when I do the search comes no results, but if I go in the bank and Zera the time works

  • Don’t get it, you save the date and time or just the date in timestamp format? The variables used for the query come in what format (datetime, date, date only, ...)? What would be "reset the hours"?

  • It worked here, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.