0

I need to get the logs of the current week in postgresql, I have tried to use the native mysql functions yearweek for that, but here in postgresql it is different

This is my table

CREATE TABLE dolar_euro(
id serial not null primary key,
monitordolar text,
bancocentral text,
eurocentral text,
fecha_registro date
);

Basically I need to get the records of the current week based on the records in the column fecha_registro

1 Answer 1

3

Use date_trunc():

select *
from dolar_euro
where fecha_registro >= date_trunc('week', current_date)

Note: Postgres understand weeks as defined by ISO, meaning that a week starts on Monday.

If your table may contain dates in the future, you might want an upper bound too:

select *
from dolar_euro
where fecha_registro >= date_trunc('week', current_date)
  and fecha_registro <  date_trunc('week', current_date) + interval '1 week'

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.