Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 164A32E0054 for ; Thu, 24 Apr 2008 11:43:56 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 69561-05 for ; Thu, 24 Apr 2008 11:43:34 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from rn-out-0910.google.com (rn-out-0910.google.com [64.233.170.186]) by developer.postgresql.org (Postfix) with ESMTP id 0319C2E0050 for ; Thu, 24 Apr 2008 11:43:42 -0300 (ADT) Received: by rn-out-0910.google.com with SMTP id i24so1575758rng.0 for ; Thu, 24 Apr 2008 07:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=hv7Uzu5TsmB1AKQSkWp7uadE60j3E1HZUSdc8XFMyrA=; b=I1NVVIMRTVAT92pYUVG3QDiFEP1/yhDILXHbLm5RGD6ga6BpHY/oFvkwHZhUonhl7EAEiCPmvMzI2N5qZKFOC89/QU+CEnidtURQHeaM6mvBqKp8o/Kj1uN4uS8pr/JXrevNjP2Y0xmg1POxYxhnVZkw0wik+F4ylD1ObfYhgPw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=PE0r5tCAEbqjyr5H+PNPKVbjU6eICAlgRj0ltOOqlM6C+js12aEpASjzIr3Q0MrZVjQAKNDOIuJN/uOdeaslZ1iTX/zPrDcSa4TqwakBljNa2MTXiZGTE9ieLpXlGcSPyeDQx81esnv+1GZPFf6GA3SWbAleALeGJJFDzEsZ2sA= Received: by 10.114.191.1 with SMTP id o1mr1841250waf.117.1209048220884; Thu, 24 Apr 2008 07:43:40 -0700 (PDT) Received: by 10.70.25.5 with HTTP; Thu, 24 Apr 2008 07:43:40 -0700 (PDT) Message-ID: Date: Thu, 24 Apr 2008 16:43:40 +0200 From: "Nacef LABIDI" To: "Colin Wetherbee" Subject: Re: First day of month, last day of month Cc: "Frank Bax" , pgsql-sql@postgresql.org In-Reply-To: <481095FB.7090600@denterprises.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_12239_30928979.1209048220838" References: <481085D1.2010807@sympatico.ca> <48108813.6070401@sympatico.ca> <481095FB.7090600@denterprises.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200804/159 X-Sequence-Number: 30698 ------=_Part_12239_30928979.1209048220838 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Actually I want to select all rows whith dates between first day of the month 00:00:00 and last date of the month 23:59:59 On Thu, Apr 24, 2008 at 4:15 PM, Colin Wetherbee wrote: > Frank Bax wrote: > > > Frank Bax wrote: > > > > > Nacef LABIDI wrote: > > > > > > > is there a better method to retrieve all the rows with dates in the > > > > current month. > > > > > > > > > > select * from mytable where extract(month from mydate) = extract(month > > > from now()) and extract(year from mydate) = extract(year from now()); > > > > > > > Sorry; I was not thinking clearly - date_trunc is better for this: > > > > select * from mytable where date_trunc('month',mydate) = > > date_trunc('month',now()); > > > > I have some code that uses extract() for this sort of thing. Would you > mind explaining how date_trunc() is better for this? > > Most of my extract() results end up in