SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast omerie63's Avatar
    Join Date
    Jul 2004
    Location
    WISCONSIN
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    interval to integer?

    What the hack?

    I am tired of this. Is there a better way to get the number of hours of difference between two timestamps than what I am doing?

    SELECT SUM(T.timeended - T.timestarted) as hoursworked
    FROM myTimes T

    This returns me an interval days, hours, minutes.

    Is there a pgsql function to convert this without me going and doing arithmetic in there, by grabing the days * 24, plus hours?

    Is there like a convert to hours function already in there that takes an interval?

  2. #2
    Non-Member
    Join Date
    Aug 2002
    Location
    USA
    Posts
    544
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be able to use something like:

    SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
    Result: 442800

    Gives the number of seconds in the interval. Multiply by 3600.

  3. #3
    SitePoint Enthusiast omerie63's Avatar
    Join Date
    Jul 2004
    Location
    WISCONSIN
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you it worked


Bookmarks

Posting Permissions

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