Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Extracting date fields from a DATE data type
On Fri, 10 Jul 1998 23:01:06 GMT, rrachamallu_at_my-dejanews.com wrote:
>Hi, I need to extract the date fields (year, month, day, hour, minute,
>second) from a date field. I could probably convert the date to char, do a
>substring operation to get the needed field, and convert it back to number.
>But this is very awkward. Is there any function that does this kind of thing
>directly?
>
>thanks.
>reddy
You can use the to_char to get just the peice of the date you want. eg.
SQL> l
1 select
2 to_number( to_char( sysdate, 'YYYY' )) year, 3 to_number( to_char( sysdate, 'MM' )) month, 4 to_number( to_char( sysdate, 'DD' )) day, 5 to_number( to_char( sysdate, 'HH24' )) hour, 6 to_number( to_char( sysdate, 'MI' )) minute, 7 to_number( to_char( sysdate, 'SS' )) second8* from dual
1998 7 14 13 11 15
I hope this helps.
chris.
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
Received on Tue Jul 14 1998 - 15:15:08 CDT
![]() |
![]() |