From: Jean-David Beyer <jeandavid8@verizon.net>
To: pgsql-sql@postgresql.org
Subject: Re: subtract two dates to get the number of days
Date: Wed, 14 Jul 2010 13:05:04 -0400
Message-ID: <4C3DEE40.1040208@verizon.net> (raw)
In-Reply-To: <i1kn9t$9e5$1@dough.gmane.org>
References: <B10E6810AC2A2F4EA7550D072CDE876004B2E65D@SAB-FENWICK.sab.uiuc.edu>
<4C3DAF72.6030606@verizon.net>
<i1kn9t$9e5$1@dough.gmane.org>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jeandavid8@verizon.net
Subject: Re: subtract two dates to get the number of days
In-Reply-To: <4C3DEE40.1040208@verizon.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox