I have two tables where I was querying on a date column in each table.
In one case need to use the trunc() function on the date field to get values back, on the other I do not.
That is this works on table 1:
SELECT to_char( datecol1 ,'mm/dd/yyyy hh:mm:ss')
FROM table1 where datecol1 =to_date('10/07/2010', 'mm/dd/yyyy');
But on table 2 the above syntax did not work and I needed the trunc(), such as:
SELECT to_char( datecol2 ,'mm/dd/yyyy hh:mm:ss')
FROM table2 where trunc(datecol2) =to_date('10/07/2010', 'mm/dd/yyyy');
Three things to note:
- in querying table1 with to_char(datecol1 ,'mm/dd/yyyy hh:mm:ss') it looks as if all the times are between 12:00 and 12:10, but values were inserted throughout the day
- when inserting records into table1 I just insert mm/dd/yyyy, no time
- when inserting records into table2 I inserted with the time
So can someone explain:
- why the truncate is not needed on table1 but on table2?
- why all values in table1 are between 12:00 and 12:10?