Re: Query to return every 1st Sat of a month between two dates

From: Osvaldo Kussama <osvaldo(dot)kussama(at)gmail(dot)com>
To: Alex - <aintokyo(at)hotmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query to return every 1st Sat of a month between two dates
Date: 2011-05-16 18:37:30
Message-ID: BANLkTi=u5P4oubo3o1Bv9rpKTFsA4AUfrg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2011/5/11 Alex - <aintokyo(at)hotmail(dot)com>:
> Hi,
> is there an easy way to return the date of every first Saturday of a month
> in a data range i.e. 2011-2013
> Any help would be appreciated
> Thanks
> Alex

Try:
SELECT s.a::date+(6-(extract(dow from s.a)::int%7)) FROM
generate_series(to_date('2011','YYYY'),to_date('2012','YYYY'), '1
month') AS s(a);

Osvaldo

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Opena 2011-05-16 18:39:44 Client-based EOFs triggering hung queries?
Previous Message Carlos Mennens 2011-05-16 18:26:21 Remove Modifiers on Table