trunc date function not working correctly
Hi,
Another quick question if people don't mind. Bit confused about the trunc date function. I'm following the sql fundamentals exam guide and using their examples:
select trunc(to_date('02-jun-2009 13:00','dd-mon-yyyy hh24:mi')) day from dual;
this returns the 2nd of june, as it should, because, as far as i'm aware, leaving the optional variable out defaults the precision to 'day'. but when i explicitly add the variable 'day', as the guide has done with 'week' 'month' and 'year' in the following examples (so i assume this format is correct rather than dd/mon/yyyy), something goes wrong:
select trunc(to_date('02-jun-2009 13:00','dd-mon-yyyy' hh24:mi'), 'day') day from dual;
this returns the 31st of may. which is incorrect.
however replacing 'day' with 'dd' provides the correct answer of the 2nd again.
this isn't a major issue, it just bothers me that the guide seems (again) to be mistaken, something that is rapidly becoming a trend in their examples. i'd also quite like to know why this is happening, as it will help improve my understanding of sql in general - perhaps there is some sort of default to allow the correct use of the variable 'day' i'm overlooking and that the guide hasn't made clear.
btw, i'm working in sqlplus - although developer has some odd results too.
thanks alot,
nick