Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle trunc with timestamp

Tags:

sql

oracle

I have a timestamp which I want to truncate. I am using the trunc funtion in oracle. This seems to do what I want however from the documentation it should only accept a date and not a timestamp

select TRUNC(TO_DATE('22-AUG-13'), 'YEAR') from dual;
select TRUNC(to_timestamp('2013-08-22 06:00:00','YYYY-MM-DD HH24:MI:SS'), 'YEAR') from dual;

Both of the above return the same result.

I presume it works because timestamp is an extension of the date format as quoted here

The TIMESTAMP data type is an extension of the DATE data type. It stores the year, month, and day of the DATE data type, plus the hour, minute, and second values. It has no time zone. The TIMESTAMP data type has the following form:

My question is what is the type of the return value? Is it always the type of the parameter value? Timestamp if parameter is timestamp. Date if parameter is date.

How can I find out the return type?

Thanks

like image 981
RNJ Avatar asked Mar 18 '23 22:03

RNJ


1 Answers

From Oracle reference:
https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions201.htm

The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt. This function is not sensitive to the NLS_ CALENDAR session parameter. It operates according to the rules of the Gregorian calendar. The value returned is always of data type DATE, even if you specify a different datetime data type for date.

like image 85
Multisync Avatar answered Mar 23 '23 04:03

Multisync