Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1AA1C9FB68C for ; Mon, 4 Jun 2007 13:25:57 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 08648-04 for ; Mon, 4 Jun 2007 13:25:52 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.250]) by postgresql.org (Postfix) with ESMTP id 6EDDE9FB59B for ; Mon, 4 Jun 2007 13:25:53 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c36so331654ana for ; Mon, 04 Jun 2007 09:25:52 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=oEJPonek8VeUjmPfkKhN2MSivTXaKac0KgC0B+tQFmS0sQAKLieFiBaZSs+HMXedzOr41DaavqqAVvHy+eoOrcQSMiaKw1Pu/ZmbgkkZmMRfe/Kmba2YxXmYaaOLoAJky7JQIlngXWuCilwZcaq+khvz5pggmebGnbzPobnzaPI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PDuGm68bcQlkNXIyzs+/lcl9CULtTNxxNS+XnJFltnm84WCggFwNlhuV4/+kMSyKeQBSZR9Vr5J1kbngWdXMQ0koJ7TT7Lp25oCcim4ZY+gdC0cN9ac2TPUAfGa9XE7FEshPMcii2zTUeBKj4p7ALImvUZl7okdL6V8BYmHsdDY= Received: by 10.100.199.12 with SMTP id w12mr2653419anf.1180974351638; Mon, 04 Jun 2007 09:25:51 -0700 (PDT) Received: by 10.100.33.20 with HTTP; Mon, 4 Jun 2007 09:25:51 -0700 (PDT) Message-ID: Date: Mon, 4 Jun 2007 11:25:51 -0500 From: "=?UTF-8?Q?Rodrigo_De_Le=C3=B3n?=" To: pgsql-sql@postgresql.org, Joshua Subject: Re: current_date / datetime stuff In-Reply-To: <46642A05.40708@joshuaneil.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46642A05.40708@joshuaneil.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/17 X-Sequence-Number: 28507 On 6/4/07, Joshua wrote: > Hello, > > I was hoping someone here may be able to help me out with this one: > > Is there anything similiar to: SELECT current_date; > that will return the date of the first Monday of the month? > > Please let me know. > > Thanks, > Joshua select ( select case i <= dow when true then d + (i - dow + 7) when false then d + (i - dow) end from ( select d , extract(dow from d)::int as dow , 1 as i -- monday from ( select date_trunc('month',current_date)::date - 1 as d ) q ) q2 ) as first_monday_of_the_month