Extract month part from date

hi,
I have a query in Informix which get the month part of a date. Please help me in converting the same to oracle.
Informix query
select month(col1 - today) from tab1;
col1 is a date field, today will yield the current date and month function will get the month of the date.
In oracle, when we subtract two dates we will get a number value, how to convert that back to date and extract the month part.
Help me?????
Regards,
Gopu

If your looking for the number of months between two dates:
SQL> select months_between(sysdate, trunc(sysdate,'yyyy')) from dual ;
MONTHS_BETWEEN(SYSDATE,TRUNC(SYSDATE,'YYYY'))
6.06223081
Just replace my usage of sysdate (etc) with the dates your using...
Hope that helped,
Stan

Similar Messages

  • Extraing Month part from date value in varchar column

    Guys,
    I have varchar2 column contains date value in the format '2013/10/03' and i want extract month part of it.
    Iam doing like this  TO_CHAR(TO_DATE(L_BATCH_DATE,'MM'))='10'   
    and it says 'not a valid month'.any ideas? and how to get that value?
    Cheers

    Hi,
      Is this are you trying.
    to_date --> we will use this function to inform oracle the date is in character mode with this format
         to_date('2013/10/03','yyyy/dd/mm')
    select to_char(to_date('2013/10/03','yyyy/dd/mm'),'mm') from dual;

  • Extract Month & Year  From Date

    Hi All,
    I have a key figure quantity and i want the data on date,for the month and for the year.
    i create the variables for the date,for the month(ie from date to date) and for the year(ie, from date to date) seperatly that means i have three input variables which may sometimes create confusion.
    My problem is that I want to enter only date and the variable itself calculate the month and year from the date so that it returns the data as desired above.
    for eg. : Now i to enter date : 3/14/2009
              enter MTD (FROM/TO) : 3/01/2009 - 3/14/2009
              enter YTD (FROM/TO) : 4/01/2008 - 3/14/2009
    I want to enter only date : 3/14/2009
    and the variable itself extract the month and year till date.
    and also the same variable calculates number of days so that need not to take the formula variable of date difference to calculate the average qty.
    Neha..

    Hi,
    1. Create User Entry Variable on 0CALDAY : Name = ZCDAY.
    2. Craete a Customer Exit Variable on 0CALDAY: Name  = ZMTD.
    3. Craete a Customer Exit Variable on 0CALDAY: Name  = YMTD.
    Properties of Customer Exit Variables.
    Variable reporesents = Single
    Variable Entry = Mandatory
    Processing By = Customer Exit.
    Character = Calender Day
    Here I'm thinking that ZKF is your key figure.
    In columns you create two selections one is for MTD and other is for YTD.
    In MTD selection, drag and drop ZKF and Drag and Drop 0CALDAY and then Right Clcik and Restrict-->
    Selection = Value Range. (In Between) and restrict with the follwoing Variables
    []ZMTD; ZCDAY.
    In YTD selection, drag and drop ZKF and Drag and Drop 0CALDAY and then Right Clcik and Restrict-->
    Selection = Value Range. (In Between) and restrict with the follwoing Variables
    []YTD; ZCDAY.
    Then write the following code in I_STEP = 2.
    DATA: ZT_DT1 TYPE SY-DATUM,
              ZT_DT2 TYPE SY-DATUM,
              ZT_SDT TYPE SY-DATUM,
              ZT_YR(4) TYPE N,
              ZT_DY(2) TYPE N,
              ZT_MT(2) TYPE N,
              ZE_TT(2) TYPE N,
              ZPOPER TYPE POPER,
             ZRELJR TYPE RELJR.
    WHEN 'ZMTD_A'.
      LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZCDAY'.
        IF sy-subrc = 0.
          CLEAR: l_s_range.
          ZT_DY = '01'.
          ZT_SDT = loc_var_range-low.
          ZT_MT = ZT_SDT+4(2).
          ZT_YR = ZT_SDT+0(4).
          CONCATENATE ZT_YR ZT_MT ZT_DY INTO ZT_DT1.
          l_s_range-low = ZT_DT1.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO e_t_range.
        ENDIF.
      ENDLOOP.
    WHEN 'ZYTD'.
      LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZCDAY'.
        IF sy-subrc = 0.
          CLEAR: l_s_range.
          ZT_DY = '01'.
          ZT_SDT = loc_var_range-low.
          CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
            EXPORTING
              I_DATE               = ZT_SDT
    *         I_MONMIT             = 00
              I_PERIV              = 'V3'
           IMPORTING
             E_BUPER              = zbuper
             E_GJAHR              = zbdatj
           EXCEPTIONS
             INPUT_FALSE          = 1
             T009_NOTFOUND        = 2
             T009B_NOTFOUND       = 3
             OTHERS               = 4
          IF SY-SUBRC <> 0.
             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          CALL FUNCTION 'FIRST_AND_LAST_DAY_IN_YEAR_GET'
            EXPORTING
              I_GJAHR              = zbdatj
              I_PERIV              = 'V3'
           IMPORTING
             E_FIRST_DAY          = ZT_DT2
    *         E_LAST_DAY           =
           EXCEPTIONS
             INPUT_FALSE          = 1
             T009_NOTFOUND        = 2
             T009B_NOTFOUND       = 3
             OTHERS               = 4
          IF SY-SUBRC <> 0.
             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          l_s_range-low = ZT_DT2.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO e_t_range.
        ENDIF.
      ENDLOOP.
    Thanks
    Reddy

  • How to get a time part from Date datatype

    Hi,
    I would like to know how to extract the timestamp alone from DATE datatype? If my input is '27-SEP-2011 23:59:00' I need the output as 23:59:00. I am surprised to see that there are no in-built functions for this or may be I am wrong. Basically I need to remove the date part from DATE data type and get the time.Please assist.
    -Thanks
    Edited by: user9546145 on Sep 27, 2011 2:24 PM
    Edited by: user9546145 on Sep 27, 2011 2:25 PM

    Hi,
    user9546145 wrote:
    Hi,
    I would like to know how to extract the timestamp alone from DATE datatype? Be careful! In Oracle, TIMESTAMP means a datatype, similar to but distinct from DATE. You'll avoid confusion if you don't use the word "timestamp" to mean anything else.
    There is a built-in function, TO_CHAR:
    TO_CHAR (dt_col, 'HH24:MI:SS')Depending on how you plan to use the time, TRUNC is another handy built-in function:
    dt_col - TRUNC (dt_col)is a NUMBER (not less than 0, but less than 1) which is suitable for many tasks, such as finding the average time.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • How to derive month/year from date in SAP BW 3.5 data flow

    Hi
    How we can derive cal year/month and fiscal month/year from date in SAP BW 3.5 data flow (we're using transfer and update rule)..
    Thanks,
    PK

    Hi,
    if you have any date filed in source side you can just map to any time char system will automatically convert to target objects.
    please look at the screen shot for understanding. (not 3.x it is 7.x)
    Thanks,
    Phani.

  • Error in running Extract Definition Upload from Data File concurrent.

    Hi all,
    Am trying to upload the 834 Extract Layout from the data file by running the concurrent program, Extract Definition Upload from Data File.
    After running this concurrent program am getting the Extract Layout definition with Record layout and Data elements within it.
    But some record layouts has the changes at their repeating level in that.
    Please suggest me how do i get the same repeating levels for the record layouts when i move the 834 benefit extract layout definition
    from one instance to another instance.

    Hi,
    We have exactly the same error in IBolt. This error happens sometime and we don't find the reason.
    IBolt has been upgraded to Version 3.1 SP1 and a fix has been developed by the support. After installation, we've work hardly during 2 days for testing all the flows by the customer without having this error.
    Ibolt works as a service and when this error occurs, the service stopped and must be restarted.
    In our flows, we have put a delete of the observer.dll file just before the rest of the flow but it doesn't solve the problem.
    Deleting the directory can be temporarly a solution but the error come back another day.
    Each time the SBO client or DTW is started, the %temp%\SMS_OBJ_DLL directory is created...
    When you just delete the observer.dll file and leave the rest of the directory like it is, the file is re-created when you start and log to SBO. I would say that this file is a copy of another file observer_800178.dll (800178 depending of the version of SBO yoi have). 800178 corresponds to SBO 2007 A PL 42.
    Do you have more information since your post has been send ?
    Thanks in advance for your help.
    Best regards.

  • How to extract local part from email address

    Hello, dear Colleagues.
    Please, help to extract local part from email address.
    Input string: "From: [email protected]"
    Need to get output string between "space" and "@": "C.Norris"
    Thanks.

    Thanks you, mjolinor.
    It works. 
    Could you show me please how to do the same with regular expression?
    Using -replace:
    $InputString = "From: [email protected]"
    $InputString -replace 'From: (.+?)@.+','$1'
    C.Norris
    Using -match:
    $InputString -match 'From: (.+?)@.+' > $null
    $Matches[1]
    C.Norris
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Extract Year/Month/ Week From Date

    BW Experts,
      I have a Time Char in a New OSD i am developing. Say the Time char is 0Req_date. This 0req_date is updated using some calculation in my update rules (Say 0Req_Date = Act_dl_dt - Conf_date). Now I have to extract month/ year/ week and populate Time Chars 0REQ_MONTH, 0REQ_YEAR and 0REQ_WEEK respectively from 0REQ_DATE. Can I do this via respective rules to 0REQ_MONTH, 0REQ_YEAR and 0REQ_WEEK in the update rules. My concern is as OREQ_DATE itself is a calculated field, can month/year/week be extracted correctly? Hope I have put the question across understandably. Help is appreciated.
    Thanks
    Ashwin

    Hi Ashwin,
    It can be done...you can either put the code for all these derivations in the Start Routine of the update rule, making sure that the 0REQ_Date is calculated before the others. Or you can also calculate just the 0REQ_DATE in the start routine and use the individual update routines to populate the other time chars.
    Processing using the Start Routine is recommended for efficiency and better performance.
    Hope this helps...

  • How to extract month number from a column in a table

    select extract(MONTH FROM DATE to_char(a.creationdate)) from mytable a doesn't work . plz tell me what is wrong with this. is there another way to get the month in a numeric form apart from this.

    Hi
    SQL> SELECT TO_NUMBER(TO_CHAR(TO_DATE('March', 'Month'), 'MM')) MONTH_NUM FROM DUAL;
    MONTH_NUM
    3
    SQL> SELECT TO_NUMBER(TO_CHAR(TO_DATE('December', 'Month'), 'MM')) MONTH_NUM FROM DUAL;
    MONTH_NUM
    12
    SQL> SELECT TO_NUMBER(TO_CHAR(TO_DATE('August', 'Month'), 'MM')) MONTH_NUM FROM DUAL;
    MONTH_NUM
    8
    This is what you want to do?
    Hope it helps
    Regards,
    Tony G.

  • FM for getting MONTH name from DATE.

    Hi all ,
    We have a requirement to get Month name from the DATE,e.g IF date is 01/01/2008 we need a FM which can generate month name as 'JANUARY'.
    \[removed by moderator\]
    Thanks and Regards
    Kiran
    Edited by: Jan Stallkamp on Jul 30, 2008 4:26 PM

    Hi,
    Here is the code u required...
    REPORT  ZASHU_MONTH_NAMES_GET.
    data:r_code type sy-subrc.
    data:mnames type standard table of T247 with header line.
    CALL FUNCTION 'MONTH_NAMES_GET'
    EXPORTING
       LANGUAGE                    = SY-LANGU
    IMPORTING
         RETURN_CODE                 = r_code
    TABLES
        month_names                 = mnames.
    EXCEPTIONS
      MONTH_NAMES_NOT_FOUND       = 1
      OTHERS                      = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    write:/ mnames.
    Thanks & Regards
    Ashu Singh

  • BI- Extract Hour:Min from date and get Avg

    Hi there,
    am working on BI answer and trying to get the average of the working hours of the departments. The Working Hrs column is Date format in the Database. And I managed with Forum help to Extract the Hours from this column and do the average through the BMM in the RPD on the Fact table as following:
    EXTRACT( HOUR FROM "Ain_Access"."Fact_Access"."Working Hours")
    Now on the BI Answer results I have 8 instead of 08:57.
    But what I need is to Extract the Hour and the minuets and get their AVG.
    Appreciate your help,

    Averaging column with date/time format in BI Answer
    this expression will work:
    (60 * EXTRACT( HOUR FROM "Ain_Access"."Fact_Access"."AVG Working Hours" ) + EXTRACT( MINUTE FROM "Ain_Access"."Fact_Access"."AVG Working Hours" )) / 60
    but only if this "AVG Working Hours" is DATE type.... and this look like strange name fore DATE? "AVG" is average, aren't?
    Arent u need to use "Working Hours" instead of "AVG Working Hours" ?
    like this:
    (60 * EXTRACT( HOUR FROM "Ain_Access"."Fact_Access"."Working Hours" ) + EXTRACT( MINUTE FROM "Ain_Access"."Fact_Access"."Working Hours" )) / 60
    all best
    phenix

  • Week and month calculation from date column

    I have 3 column data like
    with tab as
      select 'Topshop' brand, '10-JUL-11' deliverydate, '100' qty from dual union all
      select 'Topshop' brand, '10-JUL-11' deliverydate, '400' qty from dual union all
      select 'NewSita' brand, '11-JUL-11' deliverydate, '200' qty from dual union all
      select 'LaGress' brand, '12-JUL-11' deliverydate, '300' qty from dual union all
      select 'LaGress' brand, '10-AUG-11' deliverydate, '100' qty from dual union all
      select 'LaGress' brand, '11-AUG-11' deliverydate, '200' qty from dual union all
      select 'Topshop' brand, '12-AUG-11' deliverydate, '300' qty from dual union all
      select 'NewSita' brand, '10-SEP-11' deliverydate, '100' qty from dual union all
      select 'Topshop' brand, '11-SEP-11' deliverydate, '200' qty from dual union all
      select 'NewSita' brand, '12-SEP-11' deliverydate, '300' qty from dual
    ) select * from tabI need to convert it into 4 columns
    Brand | Month | Week(start date) | Qty (sum)
    Please let me know what are the options that i have, especially the date-time calculation functions available to solve such problems.
    Thanks
    w\

    with tab as
      select 'Topshop' brand, to_date('10-JUL-11', 'dd-mon-yy') deliverydate, '100' qty from dual union all
      select 'Topshop' brand, to_date('10-JUL-11', 'dd-mon-yy') deliverydate, '400' qty from dual union all
      select 'NewSita' brand, to_date('11-JUL-11', 'dd-mon-yy') deliverydate, '200' qty from dual union all
      select 'LaGress' brand, to_date('12-JUL-11', 'dd-mon-yy') deliverydate, '300' qty from dual union all
      select 'LaGress' brand, to_date('10-AUG-11', 'dd-mon-yy') deliverydate, '100' qty from dual union all
      select 'LaGress' brand, to_date('11-AUG-11', 'dd-mon-yy') deliverydate, '200' qty from dual union all
      select 'Topshop' brand, to_date('12-AUG-11', 'dd-mon-yy') deliverydate, '300' qty from dual union all
      select 'NewSita' brand, to_date('10-SEP-11', 'dd-mon-yy') deliverydate, '100' qty from dual union all
      select 'Topshop' brand, to_date('11-SEP-11', 'dd-mon-yy') deliverydate, '200' qty from dual union all
      select 'NewSita' brand, to_date('12-SEP-11', 'dd-mon-yy') deliverydate, '300' qty from dual
    ), week_data as (
       select brand
       ,      to_char(deliverydate, 'Month', 'nls_date_language=american') MON
       ,      trunc(deliverydate, 'day') WEEK_START
       ,      sum(TO_NUMBER(qty)) SUM_QTY
       from   tab
       group by brand
       ,      to_char(deliverydate, 'Month', 'nls_date_language=american')
       ,      trunc(deliverydate, 'day')
    ), weeks as (
       select
       w.week_min + (level - 1) * 7 week_start
       from (
          select min(week_start) week_min, max(week_start) week_max
          from week_data
       ) w, dual
       connect by level <= 1 + (w.week_max - w.week_min) / 7
    select
    week_data.brand,
    weeks.week_start,
    nvl(week_data.sum_qty,0) sum_qty
    from week_data
    partition by (brand)
    right outer join weeks
    on (weeks.week_start = week_data.week_start)
    order by
    weeks.week_start,
    week_data.brand;You construct a set of records of all "week_start" dates from your minimum to your maximum (classic connect by level trick.)
    You use a partitioned outer join to fill in the gaps in your sparse data (see doc example [url http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_10002.htm#i2177515]here.
    Hope that helps you :-)
    (PS. I dislike implicit conversions - that is the only reason I have added a TO_NUMBER to your code within the sum() ;-) )
    (PPS. Actually you probably should have asked this in a new question - I believe it is not really good forum etiquette to continue in a thread that has already been answered...)

  • Extract Year (only) from Date Field and Display in Text Field

    I need to extract the year from a user entered date field and display the year in a text field. Can someone help me with the correct script to do this?

    Hi,
    that's quite easy to realize with FormCalc.
    In you date fields exit event add the following code:
    textField1 = Num2Date( Date2Num($.formattedValue, "MM/DD/YYYY"), "YYYY")
    Note: This sample assumes that your date field formats the date with "MM/DD/YYYY". You may have to change the pattern to make it work at your end.

  • Extract a part from a txt file

    Hi, I've a simple problem which unfortunately can not solve.
    I have some txt's that I want only to extract a part o them. (The first 100 characters). Here is my code:
    import java.io.*;
    public class ReadSource {
         public static void main(String[] arguments) {
            try {
              FileReader file = new FileReader("1.txt");
              BufferedReader buff = new BufferedReader(file);
               boolean eof = false;
               while (!eof) {
                    String line = buff.readLine();
                    if (line == null)
                        eof = true;
                     else{
                     int start = line.indexOf("something");
                     int end = line.indexOf("something_else");
                     String str2 = line.substring(start, end);
                      System.out.println(str2);
                buff.close();
            } catch (IOException e) {
                System.out.println("Error -- " + e.toString());
    }and the error tha java displays is:
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
         at java.lang.String.substring(String.java:1438)
         at ReadSource.main(ReadSource.java:21)
    Exception in thread "main"

    Tim I'm very sorry but is still don't work. It still display the same error.
    Look at my code
    import java.io.*;
    public class ReadSource {
         public static void main(String[] arguments) {
           try {
                   BufferedReader reader = new BufferedReader(new FileReader("1.txt"));
                   BufferedWriter writer = new BufferedWriter(new StringWriter());
                   String line = null;
                   while ((line = reader.readLine()) != null) {
                       writer.write(line);
                       writer.newLine();
                   String content = writer.toString();
                   // Now you have the whole file content into the content String
                   int start = content.indexOf("smth");
                   int end = content.indexOf("smth2");
                   String str2 = content.substring(start,end);
                   System.out.println("start = "+start+", end = "+end);
                   System.out.println(str2);
               reader.close();
         }catch (IOException e) {
                System.out.println("Error -- " + e.toString());
    }It looks very logical, I don't know what happens
    Thank you very much for your help.
    Kostas

  • Year , Month & Day from Date.

    Hi HANA experts,
      Do help me to resolve this issue
    How can we extract or fetch year from the date.i went through some of the SCN blogs.where they create calculation views...but the steps are not that clear to me.
    can anyone please explain??
    My scenario is :
    I have date field in ANALYTIC VIEW which i have fetched from ECC  tables.
    now i need to get  the year  wise month wise and day wise reports. so what steps i should do in calculation view to get that??
    thanks
    Neeraja

    there is no ECC under SAP...as we are using suite on HANA fro AWS.and there is no restriction done by the basis till now...
    as we are new to these unable to trouble shoot things easily.
    thanks for your reply..

Maybe you are looking for