Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VZRnx-0006RB-0p for pgsql-sql@arkaria.postgresql.org; Thu, 24 Oct 2013 20:46:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VZRnw-0006bU-BO for pgsql-sql@arkaria.postgresql.org; Thu, 24 Oct 2013 20:46:52 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VZRnu-0006bL-1o for pgsql-sql@postgresql.org; Thu, 24 Oct 2013 20:46:50 +0000 Received: from teak.britvault.co.uk ([78.33.153.148]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VZRnl-0001BU-B0 for pgsql-sql@postgresql.org; Thu, 24 Oct 2013 20:46:48 +0000 Received: by teak.britvault.co.uk (Postfix, from userid 1970) id 3d5L8t6Pv5zBBV; Thu, 24 Oct 2013 21:46:38 +0100 (BST) Date: Thu, 24 Oct 2013 21:46:38 +0100 To: pgsql-sql@postgresql.org Subject: Number of days in a tstzrange? Message-ID: <20131024204638.GA31094@teak.britvault.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) From: skinner@britvault.co.uk (Craig R. Skinner) X-Pg-Spam-Score: 0.4 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hi folks, How can the number of days contained within a range be found? (9.2) For example, with these timestamp ranges, get these (integer) number of days: tstzrange('2013-10-01 07:00', '2013-10-01 07:15') | 1 (day) tstzrange('2013-10-01 07:00', '2013-10-01 23:45') | 1 (day) tstzrange('2013-10-01 02:00', '2013-10-02 23:45') | 2 (days) tstzrange('2013-10-01 07:00', '2013-10-03 01:00') | 2 (days) tstzrange('2013-10-01 01:00', '2013-10-03 23:00') | 3 (days) tstzrange('2013-10-01 23:00', '2013-10-04 01:00') | 4 (days) In my digging about, I've not found a builtin function for this. Is is necessary pull out the lower() and upper() timestamp elements, then get the date interval between them? Cheers, -- Craig Skinner | http://twitter.com/Craig_Skinner | http://linkd.in/yGqkv7 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql