Why does my SQL query of date fields sometimes need trunc() (Oracle)? -


i have 2 tables querying on date column in each table.

in 1 case need use trunc() function on date field values back, on other not.

that works on table 1:

select to_char( datecol1 ,'mm/dd/yyyy hh:mm:ss')  table1 datecol1    =to_date('10/07/2010', 'mm/dd/yyyy'); 

but on table 2 above syntax did not work , needed trunc(), such as:

select to_char( datecol2 ,'mm/dd/yyyy hh:mm:ss')  table2 trunc(datecol2) =to_date('10/07/2010', 'mm/dd/yyyy'); 

three things note:

  1. in querying table1 to_char(datecol1 ,'mm/dd/yyyy hh:mm:ss') looks if times between 12:00 , 12:10, values inserted throughout day
  2. when inserting records table1 insert mm/dd/yyyy, no time
  3. when inserting records table2 inserted time

so can explain:

  • why truncate not needed on table1 on table2?
  • why values in table1 between 12:00 , 12:10?

in table1 have no 'time-of-day' component data, date should match - observed. but, used mm formatting of minute part of time - mm month, not minute (mi). why see times other 12:00, , why range around 12:10 (you have data year perhaps?)

in table2, have 'time-of-day' component data, need truncate away in order match date-only value, to_date() function returns, given format have used.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -