4

how can i select only the records from DB where the Data (Date in portuguese) = the current date

SELECT id, data, dia, mes, ano,fornecedor, doc, valor_líquido, total
FROM public.fluxo_pagamentos where data = current_date;   
1
  • 2
    What is the issue with your query? Commented Jan 25, 2018 at 13:34

2 Answers 2

11

cast to date and use now()

SELECT id, data, dia, mes, ano,fornecedor, doc, valor_líquido, total
FROM public.fluxo_pagamentos where data::date = now()::date;   
Sign up to request clarification or add additional context in comments.

1 Comment

This is beautiful. Simple, straight to the point.
6

I may suspect that data has a time component. If so, try:

where data >= current_date::timestamp and
      data < current_date::timestamp + interval '1 day'

3 Comments

ERROR: operator does not exist: character varying >= timestamp without time zone LINE 2: FROM public.fluxo_pagamentos where data >= current_date::ti... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. SQL state: 42883 Character: 111
@Leogreen . . . Fix your data so dates are stored using an appropriate type.
This is complex. Use the other answer.

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.