Time handling in pgsql. (fwd)

From: nolan(at)celery(dot)tssi(dot)com
To: pgsql-general(at)postgresql(dot)org (pgsql general list)
Subject: Time handling in pgsql. (fwd)
Date: 2003-04-21 21:53:54
Message-ID: 20030421215355.9719.qmail@celery.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> is there a way taht i can cast that to say "x seconds"
> or 26:33:03:00 something like that is much more plesant
> to parse than the 1 days format.

It would be great if the 'age' function could be supplied a formatting
string so that you could format the data any way you want.

That's not an easy function to develop, though.

I recently had to write a PHP program which takes a COBOL file and
converts it to pgsql. (Yes, Virginia, there are still COBOL applications
out there!)

To complicate matters, some dates were stored 'yymmdd', some 'yyyymmdd',
some 'mmddyy' and some 'yymm'. The final one needed to be converted into
the last day of the month for pgsql purposes. (I won't get into the
kludges that were done in 1999 for Y2K 'compatibility'.)

Not all those fields had valid data in them, either.

For your purposes, you will probably have to write a function to which
you pass two timestamps. You could get lucky and find out that someone
else has already written one, but I don't see one in the 'contrib'
section of the 7.3 sources. (Are there other user-contributed code
repositories?)

Within that function convert both timestamps into seconds, do
the arithmetic and return the number of seconds.

If you know the range of dates you're likely to use, you may be
able to take a few shortcuts in that.

If you're concerned about leap years, time zones, daylight savings time,
etc, that will complicate matters.

Afterwards, please post your function so the rest of us can use it. :-)
--
Mike Nolan

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Elphick 2003-04-21 22:41:18 Re: Documentation
Previous Message Neil Conway 2003-04-21 21:47:08 Re: Are we losing momentum?