Re: Select data for current week only - Mailing list pgsql-general

From Sam Mason
Subject Re: Select data for current week only
Date
Msg-id 20090827190641.GA5407@samason.me.uk
Whole thread Raw
In response to Re: Select data for current week only  (Thomas Kellerer <spam_eater@gmx.net>)
Responses Re: Select data for current week only
List pgsql-general
On Thu, Aug 27, 2009 at 08:36:45PM +0200, Thomas Kellerer wrote:
> BlackMage wrote on 27.08.2009 20:09:
> >I only want to select events happening for the current week(Mon-Sun).
>
> SELECT *
> FROM the_table
> WHERE extract(week from the_date_column) = extract(date from current_date);

The OP leaves it somewhat open, but wouldn't date_trunc be better here?
Something like:

  SELECT * FROM the_table
  WHERE date_trunc('week',the_date_column) = date_trunc('week',CURRENT_TIMESTAMP);

Otherwise you'll end up getting values for other years as well as the
current one.

--
  Sam  http://samason.me.uk/

pgsql-general by date:

Previous
From: Gerhard Heift
Date:
Subject: Re: Select data for current week only
Next
From: Sam Mason
Date:
Subject: Re: Select data for current week only