Extract a year from a date

I have a date
 [Period Closed].[Period Closed] in a cube. This table contain only one values which might be  a certain date. Not today's date.
I have another date table where I have to use the date value from [Period Closed].[Period Closed]  and pass in to another date table so that I can drive off all my data based on the date value. There is no hierarchy in [Period Closed].[Period
Closed]  table. How can I extract year and month from [Period Closed].[Period Closed]  so that I can pass to main date table.

Try something like this:
StrToMember('[Other Date].[Other
Date]&[' + Format(CDate([Period
Closed].[Period Closed]), 'yyyyMMdd') + ']')
This assumes that the key for [Other
Date].[Other Date]
is an integer with YYYYMMDD.
Hope this helps.
Reeves
Denver, CO

Similar Messages

  • 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

  • Extracting Year from the date field

    Hi,
    I want to extract year from the date field... I've tried following code but got the error
    SELECT to_char(a.A_EXPIRY_DATE,'yyyy') as EXP_YEAR from Table_A a
    Please advice
    Thanks in advance

    user12863454 wrote:
    SELECT to_char(a.A_EXPIRY_DATE,'yyyy') as EXP_YEAR from Table_A aThis should work and returns a string.
    What error did you get?
    maybe your column name is wrong? Is it really A_somthing? This is possible but slightly unusual.
    also possible
    select extract(Year from sysdate) from dual;
    /* with your table and column */
    SELECT extract(year from a.A_EXPIRY_DATE) as EXP_YEAR from Table_A a;Edited by: Sven W. on Aug 18, 2010 6:41 PM

  • How do I pull just the year from a date?

    I'm trying to pull just the year from a date and cannot figure out how this can be done. I tried the SUBSTR fuction but its not acting how I would expect. What I'm wanting to do is write a condition that says Item Birth Year = Current Year minus 23 I have a calc that figures the age from the difference in the birthdate and current year but I'd really like to just write a condition based just one years. Can this be done?

    Hello
    SUBSTR will only work on a string. To extract portions of a date you need to use the TO_CHAR command.
    To get the year you would use this: TO_CHAR(the_date,'YYYY')
    TO_CHAR takes 2 switches, the date to be manipulated and the portion to be extracted, with the portion in single quotes.
    Once you get used to manipulating dates like this other common pieces are: DD - extracts the day of the month, MON extracts the 3 character code for the month.
    Thus you can use this: TO_CHAR(sysdate,'DD-MON-YYYY') and it will convert the current date, June 7th 2012 to 07-JUN-2012
    Hope this helps
    Best wishes
    Michael

  • How to parse the year from a date.

    Hi,
    I have the following date format in database.
    05-SEP-07
    18-OCT-07
    18-OCT-07
    25-JUL-07
    18-OCT-07
    What I am trying to do is get only the full year from the date, example
    2007
    2008
    2009
    I tried to use extract function but that doesn't work due to ORA-01843: not a valid month.
    Thanks in advance.
    select extract(year from date '18-OCT-07') from dual;

    OK. You got an error using date literal. Did you at least look in documentation on date literals? I guess not, otherwise you'd see that data literal synatx is DATE 'YYYY-MM-DD':
    SQL> select extract(year from date '18-OCT-07') from dual;
    select extract(year from date '18-OCT-07') from dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL>
    SQL> select extract(year from date '2007-10-18') from dual;
    EXTRACT(YEARFROMDATE'2007-10-18')
                                 2007
    SQL> SY.
    P.S. "I have the following date format in database" is completely wrong dates are always stored in one format - internal date format that stores year, month, day, hour, minute and second. When you select date using client tools like SQL*Plus, SQL Developer, Toad, etc. date is converted to string using either explicit or implicit format where you specify which parts of date you want to see.

  • Read Year from System Date & Compare - Assistance required

    Hi All,
    I am trying to read only the year part from the system date & then checking if any entry exists in EKKO table (EKKO-BEDAT) for the year. I think i am making an error in my data declaration for V_YEAR & in my select statement (EKKO~BEDAT LIKE V_YEAR), not sure how to compare only the year part, can someone help.
    DATA:
        V_EBELN TYPE EKPO-EBELN,
        V_YEAR  TYPE SY-DATUM.
    CLEAR: V_EBELN, V_YEAR.
    *Read year from system date
    V_YEAR = SY-DATUM+0(4).
    CONCATENATE '%' '%' '%' '%' V_YEAR INTO V_YEAR.
    *Select section
    SELECT SINGLE EKPO~EBELN INTO V_EBELN
    FROM EKPO
      INNER JOIN EKKO
        ON EKPOEBELN = EKKOEBELN
      INNER JOIN LFM1
        ON EKKOLIFNR = LFM1LIFNR
       WHERE EKKO~LIFNR = LFM1-LIFNR
         AND EKKO~BEDAT LIKE V_YEAR
         AND EKPO~LOEKZ = SPACE.

    Hi Sougata,
    Thanks for the inputs, but it is not working:
    Move:      sy-datum(4) to v_begda, -> This reads the system year 2008
            '0101'     to v_begda,  -> This changes 2008 to 0101
            sy-datum(4) to v_endda, -> This reads system year i.e. 2008
            '1231'     to v_endda. -> This changes 2008 to 1231
    Also in the select statement
    AND EKKO~BEDAT between v_begda and v_endda 
    This would not work, as EKKO-BEDAT is in year month date format.
    So can you please clarify why we are assigining 0101 & 1231 & also how we can compare only the year in EKKO-BEDAT with System Year
    Update
    I tried to
    concatenate '0101 into v_begda.
    concatenate '1231' into v_endda.
    but system prompts "charlike-field" expected after "'0101'"
    Can you please advice?
    Edited by: Vivek on Jan 5, 2008 7:59 PM

  • How to get the week number of year from a Date object?

    Hi!
    I would like to know the week number of the year from a specified Date.
    I dont know how to set the first day of week, and set the minimum days of a week.
    I want to use Monday for first day of week, and at least 4 days of month in a week.
    For example if its 1st, January is Friday, then the first week starts on 4th, Monday.
    Anyone can help?

    Sorry. I should think before I move.
         public static int getWeekOfYear(Date date) {
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(date);
             calendar.setFirstDayOfWeek(Calendar.MONDAY);
             calendar.setMinimalDaysInFirstWeek(4);
             return calendar.get(Calendar.WEEK_OF_YEAR);
         }

  • XSLT Mapping: how to calculate Week number of the year from given date

    Hi,
    I  have input as date, i need to know the Week number from that date in XSLT Coding.
    for Eg: if date is 29-12-2009 it should give 53rd week of the year.
    All answers will be appreciated.
    Regards,
    Mayank

    Hi add this statement to your XSLT Mappping
    <xsl:stylesheet version="1.0" xmlns:java="http://xml.apache.org/xslt/java" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="java">
    and use <xsl:template name="GetDateInLocal" xmlns:cal="xalan://java.util.GregorianCalendar"> in XSLT Mapping , write your logic.
    cheers,
    Raj

  • How to subtract n years from a date

    Hi all,
    I need to subtract n years from a given date..
    for example
    if date is 21.07.200<b>6</b>.. if i want to subtract 2 years (n years) i should get 21.07.200<b>4</b>

    hi,
    FM.
    CCM_GO_BACK_MONTHS
    Example
    Data : Lv_current_date type dats,
           lv_new_date     type dats,
           lv_no_months    type NUMC3.
    Lv_current_date = sy-datum.
    lv_no_months    = 12 * 2.
    CCM_GO_BACK_MONTHS
         IMPORTING
             CURRDATE   = Lv_current_date
             BACKMONTHS = lv_no_months
         EXPORTING
             NEWDATE    = lv_new_date.
    Reward Points & Mark Helpful Answers.
    to reward points ;click radio button next to the post.
    select radio button as per the answers.

  • Getting the year from the date field

    Hi,
    Please  ltet me know how to  get only YEAR form the DATE field
    Thanks in advance
    Ajay

    data:
    date like sy-datum,
    year(4) type c,
    month(2) type c,
    day(2) type c.
    year = date(4).
    month = date+4(2).
    day = date+6(2).
    Regards,
    Michael
    Please mark question as anwered if so....

  • Retrieve quarter-year from give data parameter

    Hi All,
    We are using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0.
    I want to write a query to display the records of a querter based on the input date parameter value.
    i.e. If user input 06-DEC-2010 then system should retrieve only 4th Quarter data of the Year 2010 from 01-OCT-2010 to 31-DEC-2010
    If user input 02-FEB-2010 then system should retrieve only 1st Quarter data of the Year 2010 from 01-JAN-2010 to 31-MAR-2010 (in this case only till 02-FEB-2010)
    If user input 31-DEC-2009 then system should retrieve only 4th Quarter data of the Year 2009 from 01-OCT-2010 to 31-DEC-2010
    The data column exists in the table.
    Regards,
    Hassan

    Something like
    my_date_column between trunc(p_input_date,'Q')
            and add_months(trunc(p_input_date,'Q'),3) - 1http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions220.htm#i79761
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions011.htm#i76717

  • How to determine year from a date?

    Hi experts,
    How can I deterimine the year of a datum?
    Is it always working if I determine the first 4 characters of a date?
    I mean you can write the date in many forms like. yyyy/mm/dd or dd/mm/yyyy
    So if I choose the first 4 characters the results will be different in the two cases mentioned here. How can I determine the year exactly?

    If you use internal format (fields type D, DATS) the year is always in the first 4 characters.
    Else convert into internal format first. ([CONVERT_DATE_TO_INTERN_FORMAT|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=convert_date_to_intern_format&adv=false&sortby=cm_rnd_rankvalue], [CONVERT_DATE_INPUT|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=convert_date_input&adv=false&sortby=cm_rnd_rankvalue], [CONVERSION_EXIT_DATEX_INPUT|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=conversion_exit_datex_input&adv=false&sortby=cm_rnd_rankvalue], etc.)
    Regards

  • To extract a day from a Date variable

    Hi
    I have a date variable and i want to get the day into a PL/SQL variable.Can you tell me how to do that .
    eg I have 12/30/2002 (MMDDYYY)
    and i want 30 in another variable ..
    Thanks in a advance

    SQL> declare
      2  ln number;
      3  begin
      4  ln := to_char(sysdate, 'DD');
      5  dbms_output.put_line(ln);
      6  end;
      7  /
    22
    PL/SQL procedure successfully completed.
    SQL>
    [pre]
    Piece of cake.  No, thanks, I've just had breakfast.
    APC                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Extract year from date

    Hello,
    Iam using obiee 11g, would like to extract the year from date
    CAST(YEAR("ABC"."DATEADDED" ) as varchar(4))
    so used like this
    But i want like if the year is 2011 then only 11 i wants is there a direct function which does that.
    Thanks

    You can use the right function right(year, 2). Will return 11 if year is 2011

  • Get month and year from date type

    Hi all,
    I need to get the month and year from the date type.
    For example select to_date('2011-01-17', 'yyyy-mm-dd') from dual;Result needed:
    01-2011Any ideas?
    thanks in advance,
    Bahchevanov.

    Hello Bahchevanov,
    if you need the date to compute something, then you can
    TRUNC(SYSDATE,'mm')This will give you a date with the days removed -> 01.01.2011
    Regards
    Marcus

Maybe you are looking for

  • How do you get your money back from a purchase you didn't recieve?

    I gave my girlfriend an iPhone for christmas last year and told her it was safe to shop on the app store. I have been paying for that mistake ever since. She quickly got interested in a fremium game called Dragon Vale and bought a huge pile of whatev

  • Message for down payment

    Dear Experts, When I ma posting vendor invoice or vendor payment, system is not giving message u201CDown payment exist for vendoru201D when there is down payment exist for the same vendor, I have selected u201Ccommitment warningsu201D check box in OB

  • Editing online

    Hi, I have seen a similar question, but I am not sure if that's the answer I was looking for. We have purchased a subscription online and the person who purchased it said they read something about being able to edit PDFs that have been uploaded onto

  • Ref_Cursor Issue

    Hi , I want to write an SP which should contain a sysrefcursor as O/P. The query to populate the sysrefcursor should be such that tablename,column name and value in the select query in where clause should be dynamic. What I mean is "select abc from <

  • However, we've had issues with other legacy systems and programs for outlook

    I have a user who when she logs into her workstation and tries to access her outlook folders she is denied access. If she removes and then adds them back they work. Only one other person on our network had this problem which I initially thought was c