Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: How To Extract Hour From A Date Column In A Table?
The extract function can only be used to extract the Year, Month, and
Day from a date data type. For hours, minutes, and seconds you would
have to convert the date data type to a timestamp first. Being that
you could just use to_char on the date data type, as previously pointed
out, to get the same information more efficiently why would you do to
the trouble?
select
current_timestamp CT
,to_char(sysdate,'YYYYMMDD HH24:MI:SS') CD
,extract(hour from to_timestamp(
to_char(sysdate,'DD-MON-YY HH24.MI.SS'))) as Hour
,extract(minute from to_timestamp(
to_char(sysdate,'DD-MON-YY HH24.MI.SS'))) as Minute
,extract(second from to_timestamp(
to_char(sysdate,'DD-MON-YY HH24.MI.SS'))) as Seconds
from sys.dual
/
HTH -- Mark D Powell -- Received on Wed Apr 05 2006 - 18:58:55 CDT