If the field data_venda
have not time_zone
, you can convert the dates you have into string
for date
, using the TO_DATE
and then convert to American format using the TO_CHAR
, thus:
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');
Case the field data_venda
has been time_zone
, you can do so:
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:
Without 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');
Do date commands work, for example, BETWEEN even if the field is a String and not DATE? If yes, choose the second option, American format, has occurred to me several problems with the first example, using our date formatting.
– Giancarlo Abel Giulian