Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 8A0E72E0042 for ; Thu, 24 Apr 2008 11:16:14 -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 60771-08 for ; Thu, 24 Apr 2008 11:15:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smtpauth.rollernet.us (smtpauth.rollernet.us [208.11.75.5]) by developer.postgresql.org (Postfix) with ESMTP id 2B2AD2E0037 for ; Thu, 24 Apr 2008 11:16:07 -0300 (ADT) Received: from smtpauth.rollernet.us (localhost.localdomain [127.0.0.1]) by smtpauth.rollernet.us (Postfix) with ESMTP id DCB2A594067; Thu, 24 Apr 2008 07:16:02 -0700 (PDT) Received: from iron.denterprises.org (ool-4350518d.dyn.optonline.net [67.80.81.141]) by smtpauth.rollernet.us (Postfix) with ESMTP; Thu, 24 Apr 2008 07:16:02 -0700 (PDT) Received: from [127.0.0.1] (kell.iron.denterprises.org [192.168.171.80]) by iron.denterprises.org (Postfix) with ESMTP id E38C2167636; Thu, 24 Apr 2008 10:16:01 -0400 (EDT) Message-ID: <481095FB.7090600@denterprises.org> Date: Thu, 24 Apr 2008 10:15:23 -0400 From: Colin Wetherbee User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: Frank Bax CC: pgsql-sql@postgresql.org Subject: Re: First day of month, last day of month References: <481085D1.2010807@sympatico.ca> <48108813.6070401@sympatico.ca> In-Reply-To: <48108813.6070401@sympatico.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 080424-0, 04/24/2008), Outbound message X-Antivirus-Status: Clean X-Rollernet-Abuse: Processed by Roller Network Mail Services. Contact abuse@rollernet.us to report violations. Abuse policy: http://rollernet.us/abuse.php X-Rollernet-Submit: Submit ID 5830.48109622.bd381.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/156 X-Sequence-Number: 30695 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