kausar
kausar

Reputation: 71

How to get interval from day of week from timstamp field in a table in Postgresql?

I can do the follwoing in Postgres

select interval '5 day';

Which returns

5 days

Also I can do

select (EXTRACT(DOW from i.closed_on)) || ' day' from issues i;

that results in

5 day
3 day
7 day

But I need to be able to convert this result into intervals. So I am trying to find a way to run something like

select interval (EXTRACT(DOW from i.closed_on)) || ' day' from issues i;

This gives an error.

Upvotes: 0

Views: 31

Answers (1)

inferno
inferno

Reputation: 774

This may be what you want.

postgres=# select ((EXTRACT(DOW from now())) || ' day')::interval;
 interval
----------
 5 days
(1 row)

Upvotes: 1

Related Questions