Separate time and search between dates dd / mm / yyyy

-1

I have a contracts table called contract with two columns data_ini and data_fim .

data_ini and data_fim looks like this: 04/20/2014 10:46 AM

I need to search between dates, without the time. If I did not have the time I would have it, but with the time this is difficult.

I'm trying this now

SELECT DATE_FORMAT(data_ini, '%d/%m/%Y') FROM contrato
    
asked by anonymous 20.04.2014 / 15:48

2 answers

4

It is recommended to use date fields for date and timestamp for date and time in your tables, date fields like varchar have several sorting and searching problems. To get around this use str_to_date () that converts the string to a date, the query should look like this:

SELECT * FROM contrato_reserva 
WHERE str_to_date(data_ini, "%d/%m/%Y") 
BETWEEN str_to_date('01/01/2011', "%d/%m/%Y")
and str_to_date('20/04/2014',"%d/%m/%Y")
    
20.04.2014 / 16:47
1

Try this:

SELECT date_format(data_criado, '%d/%m/%Y') FROM contrato WHERE (2014-04-22 >= data_ini) AND (2014-04-22 <= data_fim);

Or you can replace the date with "NOW ()", which is the current date. I use this to display data that are between data_ini and data_fim .

    
22.04.2014 / 18:29