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

From: Michael Nolan <htfoot(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-11 18:10:16
Message-ID: BANLkTi=DS462ZB1awq1dMD0tY=jWWZOQig@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
>
>
This is one way to do it:, there are others:

select '2011-01-01'::date + s.a as dates from generate_series(0,1095)
as s(a)
where to_char('2011-01-01'::date+s.a,'dd') between '01' and '07'
and to_char('2011-01-01'::date+s.a,'dy') = 'sat'

--
Mike Nolan

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-05-11 18:23:39 Re: Returning NULL to a set returning C type function
Previous Message Bborie Park 2011-05-11 18:01:33 Returning NULL to a set returning C type function