1

My table:

create table example
(
        code           varchar(7),
        date           date,
CONSTRAINT pk_date PRIMARY KEY (code)
);

Dates:

insert into example(code, date) 
values('001','2016/05/12');
insert into example(code, date) 
values('002','2016/04/11');
insert into example(code, date) 
values('003','2017/02/03');

My problem: how to select the previous dates to six month from today ?

In MySQL I can use PERIOD_DIFF,but, in PostgreSQL?

1 Answer 1

2

You can try INTERVAL instruction :

SELECT date
FROM example
WHERE date < CURRENT_DATE + INTERVAL '6 months'
AND date > CURRENT_DATE;

You will get the dates from today to six months.

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.