sql query to get data between two dates
I want to retrieve values from table tbl_abc
value of StartTime (the column in tbl_abc)
falls between these two time
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 ....
well you have added trunc which strips off the time part
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;
this space intentionally left blank
Click Here to Expand Forum to Full Width