Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Extracting date fields from a DATE data type

Re: Extracting date fields from a DATE data type

From: Christopher Beck <clbeck_at_us.oracle.com>
Date: Tue, 14 Jul 1998 20:15:08 GMT
Message-ID: <35abbac3.10934182@dcsun4.us.oracle.com>


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' )) second
  8* from dual
SQL> /       YEAR MONTH DAY HOUR MINUTE SECOND ---------- ---------- ---------- ---------- ---------- ----------

      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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US