Home » SQL & PL/SQL » SQL & PL/SQL » How can i extract the hour and minute from Date field using extract function?
How can i extract the hour and minute from Date field using extract function? [message #181367] Sun, 09 July 2006 05:29 Go to next message
fazal_haq2001
Messages: 35
Registered: July 2006
Location: India
Member
I cannot get to the hour/minute/second from a DATE using EXTRACT, since a DATE datatype contains a time portion as well (but not fractional seconds).

Plz help for this query...

Regards,
Fazal
Re: How can i extract the hour and minute from Date field using extract function? [message #181382 is a reply to message #181367] Sun, 09 July 2006 11:41 Go to previous message
ebrian
Messages: 2794
Registered: April 2006
Senior Member
SQL> select to_char(sysdate, 'hh24:mi:ss') "Current Time",
  2     extract(hour from to_timestamp(to_char(sysdate, 'dd-mon-yy hh24:mi:ss'))) "Hour",
  3     extract(minute from to_timestamp(to_char(sysdate, 'dd-mon-yy hh24:mi:ss'))) "Minute",
  4     extract(second from to_timestamp(to_char(sysdate, 'dd-mon-yy hh24:mi:ss'))) "Second"
  5     from dual;

Current        Hour     Minute     Second
-------- ---------- ---------- ----------
12:40:02         12         40          2


Of course you could just do the following too:

SQL> select to_char(sysdate, 'hh24:mi:ss') "Current Time",
  2     to_char(sysdate, 'hh24') "Hour",
  3     to_char(sysdate, 'mi') "Minute",
  4     to_char(sysdate, 'ss') "Second"
  5     from dual;

Current  Ho Mi Se
-------- -- -- --
12:40:10 12 40 10

[Updated on: Sun, 09 July 2006 11:51]

Report message to a moderator

Previous Topic: remove chars from string
Next Topic: Tablespace
Goto Forum:
  


Current Time: Tue Aug 19 13:15:36 CDT 2025