Re: Find Number Of Sundays Between Two Dates

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Find Number Of Sundays Between Two Dates
Date: 2008-03-05 07:11:14
Message-ID: 20080305071114.GA21973@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

am Tue, dem 04.03.2008, um 22:16:07 -0800 mailte raghukumar folgendes:
>
> Hai EverBody,
>
> Can I know what is the query by which we can find the number of
> sundays between two given dates in postgres

No problem, for instance for month january 2008:

test=*# select count(1) from
(select '2008-01-01'::date + s*'1day'::interval as datum from
generate_series(0,30) s)foo
where extract(dow from datum)=6;
count
-------
4
(1 row)

With generate_series() i generate a list of dates, and later i check if
the date are a saturday. Okay, you need to know sunday -> change from 6
to 0 and ou course, you can calculate the parameter for the
generate_series like

test=*# select count(1) from
(select '2008-01-01'::date + s*'1day'::interval as datum from
generate_series(0,'2008-01-31'::date - '2008-01-01'::date) s)foo
where extract(dow from datum)=0;
count
-------
4
(1 row)

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Garry Saddington 2008-03-05 08:09:49 Re: Find Number Of Sundays Between Two Dates
Previous Message raghukumar 2008-03-05 06:16:07 Find Number Of Sundays Between Two Dates