Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select from table by knowing only date without time (ORACLE)

Tags:

date

sql

oracle

People also ask

How do I remove the timestamp from a DATE in SQL Developer?

You can try using TRUNC() function. --- TRUNC(date_field)....in order to remove Timestamp. iif( is_date ... ( TO_CHAR(Daterec,' DD-MON-YYYY'').

How do I search for a specific DATE in Oracle?

SELECT * FROM SDE. fuse_h WHERE DATECREATED between to_date('18/01/2002','DD/MM/YYYY') and to_date('18/01/2002 23:59:59','DD/MM/YYYY HH24:MI:SS'); this will allow any index to be used that exists on the datecreated column too. Remember, always use 4 digit years when specifying dates.

Can you write a select query without the FROM clause in Oracle?

To select values from SQL expressions, a FROM clause is not strictly required as the expression is not selected from that table anyway.


DATE is a reserved keyword in Oracle, so I'm using column-name your_date instead.

If you have an index on your_date, I would use

WHERE your_date >= TO_DATE('2010-08-03', 'YYYY-MM-DD')
  AND your_date <  TO_DATE('2010-08-04', 'YYYY-MM-DD')

or BETWEEN:

WHERE your_date BETWEEN TO_DATE('2010-08-03', 'YYYY-MM-DD')
                    AND TO_DATE('2010-08-03 23:59:59', 'YYYY-MM-DD HH24:MI:SS')

If there is no index or if there are not too many records

WHERE TRUNC(your_date) = TO_DATE('2010-08-03', 'YYYY-MM-DD')

should be sufficient. TRUNC without parameter removes hours, minutes and seconds from a DATE.


If performance really matters, consider putting a Function Based Index on that column:

CREATE INDEX trunc_date_idx ON t1(TRUNC(your_date));

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'


Personally, I usually go with:

select * 
from   t1
where  date between trunc( :somedate )          -- 00:00:00
            and     trunc( :somedate ) + .99999 -- 23:59:59

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


trunc(my_date,'DD') will give you just the date and not the time in Oracle.


Simply use this one:

select * from t1 where to_date(date_column)='8/3/2010'