Make a select in a varchar column as if it were SQL datetime

1

The code is as follows:

    SELECT data 
    FROM lista 
    WHERE data BETWEEN '01-08-2015' 
    AND '05-08-2015';

The problem is that the date column is a varchar and I would like to use it as a date

    
asked by anonymous 05.08.2015 / 20:58

1 answer

2

If it is SQL you can use the convert function.

link

SQL

SELECT data 
FROM lista 
WHERE data BETWEEN convert(datetime,'01/08/2015', 103)
AND convert(datetime,'05/08/2015',103);

MySQL

SELECT data 
FROM lista 
WHERE data BETWEEN DATE_FORMAT(STR_TO_DATE('01/08/2015', '%d/%m/%Y'), '%Y-%m-%d %H:%m:%s')
AND WHERE data BETWEEN DATE_FORMAT(STR_TO_DATE('05/08/2015', '%d/%m/%Y'), '%Y-%m-%d %H:%m:%s')
    
05.08.2015 / 21:03