select data based on a date column

being_uncertain

I was trying to select some data from my table using the following query:

select * from table1 where column1 = to_date('14-05-14','yy-mm-dd');

Where the column data type is DATE. I observed that, the above query won't return anything unless we modified it as,

select * from table1 where trunc(column1) = to_date('14-05-14','yy-mm-dd');

even though there are records available.

I checked the documentation for TRUNC.Can anyone please explain why this happens?

UPDATE

As per the valuable comments I think some time values may also associated with the DATE. But I cannot view/edit that time. How can I ensure there are time values associated.

enter image description here

Dba

Both TO_DATE and TRUNC are different. See the below example.

SQL> ALTER SESSION SET nls_date_format = 'dd/mm/yyyy hh24:mi:ss';

Session altered.

SQL> SELECT TO_DATE(SYSDATE) FROM DUAL;

TO_DATE(SYSDATE)
-------------------
28/05/2014 16:03:25

SQL> SELECT TRUNC(SYSDATE) FROM DUAL;

TRUNC(SYSDATE)
-------------------
28/05/2014 00:00:00

In Your first query to_date('14-05-14','yy-mm-dd') is comparing with the date field column1 in your table which has time values also. Whereas in Your 2nd query You are truncating the time part from table data and from Your query, that's why it's matching.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Select rows based on month by using a date column in MySql

How to not select data from a column based on a condition during a select statement?

Sorting data based on column date

Select value of a column based on another column min(date) with Bigquery

How to select data from a column based on data in other columns and transpose it?

select data in pandas dataframe based on column

Consolidate multi column data frame based on ID using maximum date?

Select data based on latest transaction date for each item

Is there a way to select sum on one column based on other DISTINCT column, while grouping by third column(date) only

Spark SQL conditionally select column based on column data type

How to select based on different column data

Select weekend or weekday data from a table based on date param

SQL - Select Data Based on Date Range Efficiently

select column values based on other column date

How to select SQL Server data based on today's date and time?

Filtering rows in a data frame based on date column

Anyway to select data entered based on date it was enter in Excel vba?

Select rows based on date before an a column value which is not based on date

How to group and select data based on a date and time column over a 10-minute period?

Selectively select column data based on date range in MySQL

Select rows in a data frame based on the date range

Select data based on a day in a month, "If date is lesser than a day in a month"

How to select grouped data by date column? [ mysql ]

Select data between 2 datetime fields based on current date/time

Select column data in a table based on conditions of another column in same table

Select the min or max date based on another column in sql

How can I sort incoming data based on date column to select only latest date data for IDs?

Pandas: sequence data over date based on column change

SQL query to get data based on second table's date column