9

I'm trying this:

select * from venda where to_char(data_venda, 'MM-YYYY') = '07/2017'

Nothing returns.

The database does have two records with this date:

'21/07/2017'.

1 Answer 1

16

Use the same separator:

select v.*
from venda v
where to_char(v.data_venda, 'MM-YYYY') = '07-2017';

There are other ways to write this that don't involve changing data types:

where date_trunc('month', v.data_venda) = '2017-07-01'
where v.data_venda >= '2017-07-01' and v_data_venda < '2017-08-01'

The latter is nice, because it can readily use an index.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.