Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0qhm-0003FD-7G for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 16:12:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0qhj-0002Cg-Sh for pgsql-general@arkaria.postgresql.org; Fri, 14 Sep 2018 16:12:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0qhj-0002CN-Gq for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 16:12:23 +0000 Received: from mta1.recol.net ([64.207.103.6]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0qhg-00066x-He for pgsql-general@lists.postgresql.org; Fri, 14 Sep 2018 16:12:22 +0000 Received: from steamer.attlocal.net (162-194-37-157.lightspeed.brhmal.sbcglobal.net [162.194.37.157]) by mta1.recol.net (Postfix) with ESMTPSA id 77168398A99; Fri, 14 Sep 2018 12:12:18 -0400 (EDT) Date: Fri, 14 Sep 2018 11:10:50 -0500 From: Steven Lembark To: pgsql-general@lists.postgresql.org Cc: lembark@wrkhors.com Subject: Re: Convert interval to hours Message-ID: <20180914111050.16b7af88@steamer.attlocal.net> In-Reply-To: References: Organization: Workhorse Computing X-Mailer: Claws Mail 3.17.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 14 Sep 2018 11:55:18 -0400 Peter Kleiner wrote: > On Fri, Sep 14, 2018 at 11:51 AM David Gauthier > wrote: > > > > Hi: > > > > In perl/DBI, I have code that's getting me an "age" which returns > > something like... "-17 days -08:29:35". How can I convert that to > > a number of hours (as a float I would presume) ? Suggest using one of the date modules. One issue is that not all days are 86400s long: "leap second" is used to keep atomic clocks in sync with siderial time so that telescopes report consistent values over time. Catch is that simply dividing by 3600 doesn't always work if the times fall across the wrong days. You would normally want an integer for these rather than float as the result to avoid rounding issues on extract or with comparisions in or out of the database. You will normally not have more than one second precision on times (timestamps are a different matter). Q: What database are you using? Postgres makes it easy enough to cast the values or compute the difference is seconds. -- Steven Lembark 3920 10th Ave South Workhorse Computing Birmingham, AL 35222 lembark@wrkhors.com +1 888 359 3508