Working with dates

Started by Ranieri Mazilialmost 19 years ago2 messagesgeneral
Jump to latest
#1Ranieri Mazili
ranieri.oliveira@terra.com.br

Hello,

I need to do the following select:

Number of days of month - weekends - holydays

So this query will return the number of days that people can work

Look that I have the holydays in one table, it's bellow:

CREATE TABLE holidays
(
id_holidays serial NOT NULL,
dt_holiday date,
holiday_description character varying(60),
input_date timestamp without time zone NOT NULL,
CONSTRAINT holidays_pkey PRIMARY KEY (id_holidays)
)

I have no idea of how do it

If someone could help, I would appreciate.

Thanks

#2Ranieri Mazili
ranieri.oliveira@terra.com.br
In reply to: Ranieri Mazili (#1)
Re: Working with dates

-------- Original Message --------
Subject: [GENERAL] Working with dates
From: Ranieri Mazili <ranieri.oliveira@terra.com.br>
To: pgsql-general@postgresql.org, pgsql-sql@postgresql.org
Date: 5/7/2007 16:00

Hello,

I need to do the following select:

Number of days of month - weekends - holydays

So this query will return the number of days that people can work

Look that I have the holydays in one table, it's bellow:

CREATE TABLE holidays
(
id_holidays serial NOT NULL,
dt_holiday date,
holiday_description character varying(60),
input_date timestamp without time zone NOT NULL,
CONSTRAINT holidays_pkey PRIMARY KEY (id_holidays)
)

I have no idea of how do it

If someone could help, I would appreciate.

Thanks

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

I can.

select count(A.data)
from (select (date_trunc('month',(select production_date from production
order by production_date desc limit 1)::date)::date + x * '1
day'::interval)::date as data from generate_series(0,31) x) A
where extract(month from A.data) = extract(month from (select
production_date from production order by production_date desc limit
1)::date )
and extract(dow from A.data) <> 0
and extract(dow from A.data) <> 6
and A.data not in (select dt_holiday from holidays)