show table data between two dates chosen (dates are in varchar)

0
SELECT * FROM minhaTabela WHERE status=2
AND nomePessoa='Jose Silva' AND STR_TO_DATE(data_enviado, '%d/%m/%Y')
BETWEEN STR_TO_DATE('01/05/2015', '%d/%m/%Y')
AND STR_TO_DATE('31/06/2015', '%d/%m/%Y')

is there any way to do an if / else? I have other tables that date do not follow this pattern of day / month / year (this is already treated there above). some tables, column data_enviado , is like year-month-day , some others such as year / month / day , others like day-month-year ; I could do the processing in my php code by checking the name of the tables, but if there is an easier way to do this through sql ...

    
asked by anonymous 30.06.2015 / 23:10

1 answer

0

Jerry , try:

SELECT * 
FROM 
     minhaTabela
WHERE 
      status=2 AND 
      nomePessoa='Jose Silva' AND 
      DATE_FORMAT(str_to_date(data_enviado, '%d/%m/%Y'), '%Y-%m-%d')
      BETWEEN DATE_FORMAT(str_to_date('01/05/2015', '%d/%m/%Y'), '%Y-%m-%d') AND
      DATE_FORMAT(str_to_date('31/06/2015', '%d/%m/%Y'), '%Y-%m-%d');
    
30.06.2015 / 23:35