DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: sql query to get data between two dates

  1. #1
    Join Date
    Aug 2009
    Posts
    2

    sql query to get data between two dates

    Hi
    I want to retrieve values from table tbl_abc
    where the
    value of StartTime (the column in tbl_abc)

    falls between these two time

    2009-07-15 09:57:24.0
    2009-07-15 09:58:24.0

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    so whats the problem?

  3. #3
    Join Date
    Aug 2009
    Posts
    2

    Unhappy

    I need to write an SQL query for the same ..

    I am ableto retrive values between two dates '2009-07-15' and '2009-07-16' but
    not when the two dates are same but time is different....

    select * from tbl_abc where trunc(StartTime) between to_date('2009-07-15', 'YYYY-MM-DD') and to_date('2009-07-16', 'YYYY-MM-DD');

    but this will not work for same dates ....

  4. #4
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    well you have added trunc which strips off the time part

  5. #5
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166
    If you subtract one date from another you will get the time difference in days.
    Then multiply by 24 and you will get the time difference in hours, etc.

    SYS AS SYSDBA> select (sysdate-(sysdate-5/24))*24 from dual;

    (SYSDATE-(SYSDATE-5/24))*24
    ---------------------------
    5

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