Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0EE44632AF0 for ; Wed, 14 Jul 2010 14:05:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 06553-04 for ; Wed, 14 Jul 2010 17:05:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from vms173003pub.verizon.net (vms173003pub.verizon.net [206.46.173.3]) by mail.postgresql.org (Postfix) with ESMTP id F0D29632768 for ; Wed, 14 Jul 2010 14:05:27 -0300 (ADT) MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset=windows-1252 Received: from trillian.localdomain ([unknown] [96.240.12.15]) by vms173003.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0L5K00EUZ4SG38E0@vms173003.mailsrvcs.net> for pgsql-sql@postgresql.org; Wed, 14 Jul 2010 12:05:05 -0500 (CDT) Message-id: <4C3DEE40.1040208@verizon.net> Date: Wed, 14 Jul 2010 13:05:04 -0400 From: Jean-David Beyer Organization: Institute for Regimented Whimsey User-Agent: Thunderbird 2.0.0.24 (X11/20100318) To: pgsql-sql@postgresql.org Subject: Re: subtract two dates to get the number of days References: <4C3DAF72.6030606@verizon.net> In-reply-to: X-Enigmail-Version: 0.96.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-5 required=5 tests=BAYES_40=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/69 X-Sequence-Number: 34382 Thomas Kellerer wrote: > Jean-David Beyer wrote on 14.07.2010 14:37: >> My dates are of the form yyyy-mm-dd and such. > Storing a date as a string is never a good idea. I started this long ago, when postgreSQL did not really work very well (1998?). One version of it would not do views, and another had trouble with primary keys, IIRC. So I first used Informix, until it would not work any more. It did not really support embedded SQL in C++, only in C, so that was a pain. But it quit working when Red Hat updated from release 5 to release 6. I then moved to IBM's DB2, and that worked very well, but it got too expensive to keep it when I went from one release of my OS to another for just my own workstation use. Somewhere around 2004, or a little before, I decided to give postgreSQL another chance, and it works just fine. I just looked them up in my data definitions. Dates are _stored_ as type DATE NOT NULL so I store them OK. It is just when I want to compute with them that it gets a bit tricky. Or it did way back when I wrote that stuff in the late 1990s. > >> And I want to do things like adding or subtracting days, months, or years to it or from it. >> Also the logical comparisons. > Which is all a piece of cake when you use the proper datatype Yes, if the data happen to be stored at all. But when a program generates the dates dynamically and wants to produce queries from them, it is easier to use the C++ class to generate the dates. > >> Years ago, I made a C++ data type that allowed a date datatype where I >> could add, subtract, and so on. >> I use it in programs that do not necessarily use a database, > To be honest: I expect the programming language to support those things. I would love it. For all I know, the C++ Standard Library supports it now, but I do not believe it did when I wrote that class. > >> but also in programs that do when the computations are the big part of the cpu load, >> as contrasted to just "gentle" massaging of existing data. > I would expect doing "date maths" with strings is wasting more CPU than using a native date datatype. My class pretty much does not do it as strings, but as integers (internally) > > Just my €0.02 > Thomas > Well, €0.02 is still more than my US$0.02, I believe. -- .~. Jean-David Beyer Registered Linux User 85642. /V\ PGP-Key: 9A2FC99A Registered Machine 241939. /( )\ Shrewsbury, New Jersey http://counter.li.org ^^-^^ 12:45:01 up 6 days, 21:31, 4 users, load average: 4.65, 4.69, 4.71