I'm trying to retrieve records from table by knowing the date in column contains date and time.
Suppose I have table called t1
which contains only two column name
and date
respectively.
The data stored in column date like this 8/3/2010 12:34:20 PM
.
I want to retrieve this record by this query for example (note I don't put the time):
Select * From t1 Where date="8/3/2010"
This query give me nothing !
How can I retrieve date
by knowing only date
without the time?
Personally, I usually go with:
select *
from t1
where date between trunc( :somedate ) -- 00:00:00
and trunc( :somedate ) + .99999 -- 23:59:59
Try the following way.
Select * from t1 where date(col_name)="8/3/2010"
trunc(my_date,'DD')
will give you just the date and not the time in Oracle.
You could use the between function to get all records between 2010-08-03 00:00:00:000 AND 2010-08-03 23:59:59:000
Simply use this one:
select * from t1 where to_date(date_column)='8/3/2010'
Convert your date column to the correct format and compare:
SELECT * From my_table WHERE to_char(my_table.my_date_col,'MM/dd/yyyy') = '8/3/2010'
This part
to_char(my_table.my_date_col,'MM/dd/yyyy')
Will result in string '8/3/2010'
Source: Stackoverflow.com