Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AC271476026 for ; Thu, 26 Sep 2002 12:38:58 -0400 (EDT) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 462F9475EF9 for ; Thu, 26 Sep 2002 12:38:58 -0400 (EDT) Received: by news.hub.org (Postfix, from userid 8) id 42F9338164D; Thu, 26 Sep 2002 12:39:01 -0400 (EDT) From: Dmitry Tkach X-Newsgroups: comp.databases.postgresql.sql Subject: Re: start and end of the week Date: Thu, 26 Sep 2002 12:29:05 -0400 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 32 Message-ID: <3D9335D1.4040807@openratings.com> References: <20020926162029.GA23728@wolff.to> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: news@hub.org To: Bruno Wolff III User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7+) Gecko/20020123 X-Accept-Language: en-us To: pgsql-sql@postgresql.org X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/327 X-Sequence-Number: 9604 Does any one know what is the reason not to put this logic into date_trunc () function? It seems to work with pretty much *any* unit imaginable, *except* for 'week'... Dima Bruno Wolff III wrote: > On Thu, Sep 26, 2002 at 11:55:48 -0400, > Jean-Luc Lachance wrote: > >>How about: >> >>select now() - date_part( 'DOW', now()) as starts_on, >> now() -date_part( 'DOW', now()) + 6 as ends_on; >> > > That won't work in 7.3. > > The following works in both 7.2 and 7.3: > area=> select current_date - extract(dow from current_date)::int as start_date, > area-> current_date - extract(dow from current_date)::int + 6 as end_date; > start_date | end_date > ------------+------------ > 2002-09-22 | 2002-09-28 > (1 row) > > Extract returns double precision and so needs a cast to int to work. > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster >