Comparison of two dates using varchar type MySQL

0

I have a question regarding the preparation of a SQL query in which I pass a registration date and check if it is larger than the current date, but I have a problem the date of registration is varchar and it follows the format "dd / mm / yyyy ", follow below to select:

SELECT * FROM Evento 
WHERE data_evento > curdate()
ORDER BY idEvento ASC LIMIT 0,3;
    
asked by anonymous 05.07.2017 / 20:26

2 answers

1

Convert the field to date on own SELECT using the STR_TO_DATE function:

SELECT * FROM Evento 
WHERE STR_TO_DATE(data_evento, "%d/%m/%Y") > curdate()
ORDER BY idEvento ASC LIMIT 0,3;
    
05.07.2017 / 20:30
0

Syntax for CAST: CAST (expression AS data_type [(length)]) Syntax for CONVERT: CONVERT (data_type [(length)], expression [ style])

    
05.07.2017 / 20:30