Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TSy3f-0002n9-V4 for pgsql-sql@postgresql.org; Mon, 29 Oct 2012 22:43:48 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TSy3e-0007Mc-6S for pgsql-sql@postgresql.org; Mon, 29 Oct 2012 22:43:46 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1TSy3g-00024F-K1 for pgsql-sql@postgresql.org; Mon, 29 Oct 2012 23:43:48 +0100 Received: from ppp-188-174-101-16.dynamic.mnet-online.de ([188.174.101.16]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 29 Oct 2012 23:43:48 +0100 Received: from spam_eater by ppp-188-174-101-16.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 29 Oct 2012 23:43:48 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Thomas Kellerer Subject: Re: Fun with Dates Date: Mon, 29 Oct 2012 23:44:01 +0100 Lines: 24 Message-ID: References: <508F0576.4020404@noaa.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ppp-188-174-101-16.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: <508F0576.4020404@noaa.gov> X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201210/58 X-Sequence-Number: 36929 Mark Fenbers wrote on 29.10.2012 23:38: > Greetings, > > I want to be able to select all data going back to the beginning of > the current month. The following portion of an SQL does NOT work, > but more or less describes what I want... > > ... WHERE obstime >= NOW() - INTERVAL (SELECT EXTRACT (DAY FROM NOW() > ) ) + ' days' > > In other words, if today is the 29th of the month, I want to select > data that is within 29 days old... WHERE obstime >= NOW() - INTERVAL > '29 days' > Or the other way round: anything that is equal or greater than the first of the current month: select ... from foobar where obstime >= date_trunc('month', current_date); Thomas