How would it be possible to perform the following consultation?

0
SELECT * FROM 'ofertas' WHERE date LIKE '2016-12-20%' BETWEEN LIKE '2017-01-16%'

I would like to consult a range of dates, but the column date is declared with the default CURRENT_TIMESTAMP , so when making the query with the clause BETWEEN , you would also have to enter the record time '.

Is it possible to make this query with only the date and not the time, without having to modify the structure of the table because the time is used in other sections of the system?

    
asked by Sergio 23.01.2017 в 19:00
source

2 answers

1

You could use a query like this:

SELECT * FROM ofertas WHERE date >= '2016-12-20 00:00:00' AND date <= '2017-01-16 23:59:59'

Or you could even use the between SQL function:

SELECT * FROM ofertas WHERE date BETWEEN '2016-12-20 00:00:00' AND '2017-01-16 23:59:59'

What you do is set the time values in a static way, the only thing that you would have to change is the date.

    
answered by 23.01.2017 / 19:02
source
0

You could use DATE() to convert to date the value of the column datetime .

So for example:

SELECT * FROM 'ofertas' WHERE DATE(date) BETWEEN '2016-12-20' AND '2017-01-16'
    
answered by 23.01.2017 в 21:57