From: | Jaime Casanova <jaime(at)2ndquadrant(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-17 22:00:22 |
Message-ID: | BANLkTimx45VrjXA6KJMU3TCuXFqe_zAO=Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, May 11, 2011 at 10:22 AM, Alex - <aintokyo(at)hotmail(dot)com> wrote:
> 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
if you want a list of the first saturdays of every month and you're
using at least 8.4:
with q as (select d, lag(d) over ()
from generate_series('2011-02-01'::date, now()::date, '1
day') as s(d)
where extract(dow from d) = 6
)
select d from q where (lag is null) or (extract(month from d) <>
extract(month from lag));
where '2011-02-01' is the initial date and now()::date - '1 day' the
final one, replace them with you're own range
--
Jaime Casanova www.2ndQuadrant.com
Professional PostgreSQL: Soporte y capacitación de PostgreSQL
From | Date | Subject | |
---|---|---|---|
Next Message | G. P. | 2011-05-17 23:13:28 | Re: re-install postgres/postGIS without Loosing data?? |
Previous Message | G. P. | 2011-05-17 21:54:12 | re-install postgres/postGIS without Loosing data?? |