If the data_venda
field does not have time_zone
, you can convert the dates you have in string
to date
, using TO_DATE
and then convert to American format using TO_CHAR
like this:
SELECT * FROM vendas
WHERE data_venda
BETWEEN TO_CHAR(TO_DATE('01/03/2016', 'DD-MM-YYYY'), 'YYYY-MM-DD')
AND TO_CHAR(TO_DATE('16/10/2016', 'DD-MM-YYYY'), 'YYYY-MM-DD');
If the data_venda
field has time_zone
, you can do this:
SELECT * FROM vendas
WHERE TO_CHAR(data_venda, 'YYYY-MM-DD') --Convertendo para o formato americano
BETWEEN TO_CHAR(TO_DATE('01/03/2016', 'DD-MM-YYYY'), 'YYYY-MM-DD')
AND TO_CHAR(TO_DATE('16/10/2016', 'DD-MM-YYYY'), 'YYYY-MM-DD');
Simplified form:
No timezone
SELECT * FROM vendas
WHERE data_venda
BETWEEN TO_CHAR('01/03/2016'::DATE, 'YYYY-MM-DD')
AND TO_CHAR('16/10/2016'::DATE, 'YYYY-MM-DD');
With timezone
SELECT * FROM vendas
WHERE TO_CHAR(data_venda, 'YYYY-MM-DD') --Convertendo para o formato americano
BETWEEN TO_CHAR('01/03/2016'::DATE, 'YYYY-MM-DD')
AND TO_CHAR('16/10/2016'::DATE, 'YYYY-MM-DD');