Query return data between two fixed points in time.
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Query return data between two fixed points in time.

  1. #1
    Join Date
    Mar 2004
    Posts
    55

    Query return data between two fixed points in time.

    I have a table with a datestamp column which indicates wheren the record was written to the database table.

    I am trying to write a query that will return all records that are in a date range between 6am (today) and 6am (a week ago).

    I understand how to do the date range part however unsure how to enforce the 6am condition.

    The query needs to be able to be run without changing the query on a regular basis. I should be able to run the query at any time during the day and it should stick to return only records between 6am 7 days ago and 6am today.

    i have written thusfar

    SELECT xxxx.table
    FROM table
    WHERE to_date(reportdate,'DD/MM/YYYY')
    BETWEEN to_date(sysdate-7,'DD/MM/YYYY')
    AND to_date(reportdate,'DD/MM/YYYY')

    Thankyou
    Last edited by mozart; 11-15-2006 at 05:18 PM.

  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    SELECT xxxx.table
    FROM table
    WHERE reportdate
    BETWEEN (trunc(sysdate) - 7 )+6/24
    AND trunc(sysdate)+6/24
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  3. #3
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,026
    What about this?

    Code:
    SELECT xxxx.table
      FROM table
     WHERE to_date(reportdate,'DD/MM/YYYY')
           BETWEEN TRUNC(sysdate) - 7 + 6/24
               AND to_date(reportdate,'DD/MM/YYYY') + 6/24;
    this space intentionally left blank

Posting Permissions

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


Click Here to Expand Forum to Full Width