Results 1 to 2 of 2

Thread: About Intervals

  1. #1
    Join Date
    Dec 2003
    Posts
    11

    Unanswered: About Intervals

    Hi.

    Well, I'm having some problems with intervals. Maybe someone could help me.

    I'm using postgreSQL 7.3.3, Java and JfreeReport to deploy an application. Everythink is fine, but now I have a problem.

    To generate a report, a need to calculate some intervals. For example
    SELECT final_date - initial_date FROM someTable ;
    and that will give me the desired interval. But, when I try to get that interval in Java, I get this message "No class found for interval". I already asked at JFreeReport forum, and there, they told me it is possible a jdbc driver bug, but I'm using the latest jdbc driver for postgreSQL.

    They suggested me to cast the interval to a date type, and maybe that would work. But, I don't know if it is possible. I tried :

    SELECT date(final_date - initial_date) FROM someTable ; but I received this message: Bad date external representation '00:24'.

    Is there a way to cast an interval to a date ? or maybe someone know how to get an interval from a ResultSet from Java.

    Thanks for any help.
    Pablo Velasquez Rivas
    Computer Science Engineer - ITCR

  2. #2
    Join Date
    Feb 2004
    Posts
    14
    How about this?

    Code:
    template1=# SELECT EXTRACT(epoch FROM ('Feb 16 2004 16:00'::timestamp - 'Feb 15 2004 15:00'::timestamp)::interval) AS secs;
     secs
    -------
     90000
    (1 row)
    As you can see, selecting the 'epoch' part of the interval will return the interval's representation in seconds. I presume you can take it from there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •