Extracting year and date

I am working on the following query
SELECT report_date, EXTRACT (MONTH FROM report_date) FROM program_details;
SELECT a.customer_id, a.report_date as change_date
FROM program_details AS a
LEFT JOIN program_details AS b
on a. customer_id = b. customer_id
AND EXTRACT (MONTH FROM a.report_date) = EXTRACT (MONTH FROM b.report_date) - 1
AND EXTRACT (YEAR FROM a.report_date) = EXTRACT (YEAR FROM b.rpt_date )
WHERE a.code_status = 'Gold' and b.code_status = 'Plat'
AND a.report_date >= '2007-12-01 00:00:00.0'
AND a.report_date < '2009-01-01 00:00:00.0'
I have a table with customer id, yyyy-mm-dd for many years , and status as gold silver or platinum. and I need to work out the month that the status changed, and return a field as year-month.
I am trying to extract the year and date that a customer changed from gold to plat but I am not sure how date arithmetic works. I need to have output like : customer_id and year-month but I keep just getting month.
I know this is vague, but if you could help with the part of the query that delivers year and month back that would be great.
Thank you very much

Hi,
  1  SELECT a.customer_id, to_char(a.report_date, 'yyyy-mm') as change_date
  2* FROM program_details a
SQL> /
CUSTOMER_ID CHANGE_
          1 2009-06Bartek

Similar Messages

  • Return current period based off of current fiscal year and date

    Good Afternoon,
    Is there a way in the webi that I can create a dimension that always reflects the current Fiscal Month based of Fiscal year and date? I have a report that I am trying to show sales for a customer based off the current fiscal month. I would like this report when refreshed to be based off this fiscal month dimension instead of showing each fiscal month or changing it manually. What is the best way to do this?
    I have attached an image that shows current numbers by period (month) and then the YTD Totals. I would like to have my 'Period' column always reflect the current period and the Total column to reflect that months totals based off the period column. So for this period (3), instead of seeing 3 lines for each month I would just see the '3' and the total as $541,310.46, monthly as 412,502.09 and my YTD as 1,080,091.06.
    Any help is always appreciated!
    Thank you,
    Tiffany

    Hi,
    Create a variable
    FlagVar=If([Period]=Max([Period]) In Report;"Show";"Hide")
    And apply block filter of FlagVar=Show
    Are these coming TotalSales  MonthlyGoal YTDSales directly from universe? If they are calculated at report level then you might want to use NoFilter. like =NoFilter([YTDSales])

  • 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

  • Extract time and data with a regular expression

    Hi,
    I have a string with time and date in a HTML statement.
    String s =">19:59, 18 August 2006</a> ";
    // I hope get
    String s1="19:59, 18 August 2006";or
    String s =">18:37, 4 September 1998</a>"Because of different length of months, so how use regular expression to extract it.
    The second question is how to write the string into a file.
    filename =  "A.txt";
                    File file = new File(filename);
              out=new BufferedOutputStream(
                        new FileOutputStream(file));
                   byte[] buffer = new byte[1024];
    // then what?Thank you in advance!

    If "WARNING" can never occur in the input then wedon't have to worry about making the regex not match
    it.
    Hmm, how about fool-proof? :)Bad idea, and impractical or impossible to implement. Excessively defensive coding leads to bloated, hard to maintain code, and a greater likelihood of bugs.
    Code so that you code works correctly provided the preconditions are met. It's the caller's responsibility to meet them. Don't waste time and gunk up your code trying to handle inputs that aren't allowed to occur.

  • Extract year from date and exclude Null

    I have a calculated column that will pull the year out of a date column:
    =TEXT([Date Impact Identified],"yyyy")
    This formula works fine but if the column is blank then it returns the value as 1899. I have tried several variations of ISBLANK or ="" but nothing has worked so far. I think I am putting the formula in the wrong order. Can anyone help?
    Thanks.

    Hello,
    In order to save you weeding through other threads, here's what should work in your scenario:
    =IF(ISBLANK([Date
    Impact Identified]),"",TEXT([Date
    Impact Identified],"yyyy"))
    cheers, teylyn

  • Multi-month, year, and date-range views

    My apologies for wasting everyone's time if I've missed something really obvious here, but am I correct in concluding that there is no way to generate anything beyond a static one-month view in iCal? No multi-month view? No year view? No "view date range"? At this stage of the game, how is it possible that something so elemental could be omitted from this program?
    At this point I'm reduced to exporting each month to a pdf file and then arranging them as tiles on the screen. But there has to be a better way.
    Short of a new version from Apple, are there any plug-ins that would do this? Does anyone have any other work-arounds? Thanks in advance.

    A quick search of the forums shows that this is a HIGHLY sought after feature (including by me). We all need to use the feed back link (below) to let Apple know this. In my experience with the tech support folks, they seem to have NO idea about what these forums say. In the past I have actually had them log in to these forums and search the issue I was calling them about and they have been blown away when they see the hundreds / thousands of posts with the very same thing they're discussing with me. So, as the wise man says .. "you don't ask, you don't get!" Use the form and let them know...
    http://www.apple.com/feedback/ical.html

  • EXTRACTING XML AND DATE FORMAT

    Hello,
    I want to extract data from XML using the following syntax.
    But I don't get why I get ORA-01830 exception while extracting DATE in YYYY-MM-DD HH24:MI:SS format.
    Can you help me ?
    alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS';
    select e.*
    from (select xmltype('<root><my_date>2012-04-05</my_date></root>') as dt from dual) t,
    xmltable('root'
    passing t.dt
    columns
    my_date date path'my_date'
    ) e;
    select e.*
    from (select xmltype('<root><my_date>2012-04-05 14:35:20</my_date></root>') as dt from dual) t,
    xmltable('root'
    passing t.dt
    columns
    my_date date path'my_date'
    ) e;
    SQL> alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS';
    Session modifiÚe.
    SQL>
    SQL>
    SQL> select e.*
    2 from (select xmltype('<root><my_date>2012-04-05</my_date></root>') as dt fr
    om dual) t,
    3 xmltable('root'
    4 passing t.dt
    5 columns
    6 my_date date path'my_date'
    7 ) e;
    MY_DATE
    2012-04-05 00:00:00
    SQL>
    SQL> select e.*
    2 from (select xmltype('<root><my_date>2012-04-05 14:35:20</my_date></root>')
    as dt from dual) t,
    3 xmltable('root'
    4 passing t.dt
    5 columns
    6 my_date date path'my_date'
    7 ) e;
    select e.*
    ERREUR Ó la ligne 1 :
    ORA-01830: Le modÞle du format de date se termine avant la conversion de la
    cha¯ne d'entrÚe entiÞre

    From 10g and onwards, Oracle doesn't rely on NLS date settings to handle dates in XML.
    The supported formats are those of the ISO 8601 : http://www.w3.org/TR/xmlschema-2/#isoformats
    SQL> select e.*
      2  from xmltable(
      3        '/root'
      4        passing xmltype('<root><my_date>2012-04-05T14:35:20</my_date></root>')
      5        columns
      6          my_date timestamp path 'my_date'
      7       ) e ;
    MY_DATE
    05/04/12 14:35:20,000000
    SQL>
    SQL> select e.*
      2  from xmltable(
      3        '/root'
      4        passing xmltype('<root><my_date>2012-04-05</my_date></root>')
      5        columns
      6          my_date date path 'my_date'
      7       ) e ;
    MY_DATE
    05/04/2012
    If your date string doesn't conform to the supported formats, use a VARCHAR2 datatype and an explicit TO_DATE in the SELECT :
    SQL> select to_date(e.my_date, 'YYYY-MM-DD HH24:MI:SS') as my_date
      2  from xmltable(
      3        '/root'
      4        passing xmltype('<root><my_date>2012-04-05 14:35:20</my_date></root>')
      5        columns
      6          my_date varchar2(30) path 'my_date'
      7       ) e ;
    MY_DATE
    05/04/2012

  • Ical displays the wrong year and date, how do I reset it?

    My ical date is currently 2555 BE. I can get to a specific date but I am unable to set it to the correct date. Please help...

    it is the Buddhist Cal but I do not know who to change it!  I need help changing it back!

  • Extract Data Based on Year and Month

    My clients have taken an Oracle DB TimeStamp field and
    downloaded it to Access in a TEXT field format.
    Sample data: 20060401001348CS
    All I am trying to do is extract data based on year and
    month. I have equal to 200604*, 200604%. Have also tried to used
    LIKE.
    Nothing works. It just can't be that dificult. Please help.
    Thanks

    After breaking my inquiry down into bits and pieces the
    problem is not just the LIKE, it is a combination of events. The
    entire picture is this:
    User selects Year from a drop down (2006), then selects month
    from drop down (04). I then build a variable called
    EventReport Date with the statement <cfset EventReportDate
    = Session.InquiryYear & Session.InquiryMonth & "%">
    It correctly displays as 200604% - When used by itself as
    below, it works just fine.
    WORKS
    <cquery name="GetEventCount" datasource="CountyDB">
    Select count(AD_ID) as EventCount, TYCOD, TYP_ENG, CURENT,
    CDTS
    FROM aeven
    WHERE CDTS LIKE '#EventReportDate#'
    Group By AG_ID, TYCOD, TYP_ENG, CURENT, CDTS
    </cfquery>
    WORKS (additional WHERE criteria)
    <cquery name="GetEventCount" datasource="CountyDB">
    Select count(AD_ID) as EventCount, TYCOD, TYP_ENG, CURENT,
    CDTS
    FROM aeven
    WHERE ((AG_ID = '#Session.InquiryAgencyCode#') AND (CURENT =
    'T'))
    Group By AG_ID, TYCOD, TYP_ENG, CURENT, CDTS
    </cfquery>
    FAILS **** There is something wrong with the combination of
    the WHERE clause items
    <cquery name="GetEventCount" datasource="CountyDB">
    Select count(AD_ID) as EventCount, TYCOD, TYP_ENG, CURENT,
    CDTS
    FROM aeven
    WHERE ((AG_ID = '#Session.InquiryAgencyCode#') AND (CURENT =
    'T')
    AND (CDTS LIKE '#EventReportDate#'))
    Group By AG_ID, TYCOD, TYP_ENG, CURENT, CDTS
    </cfquery>
    NOTE: There is not an error message, it just comes back with
    zero records.
    MORE LOST THAN EVER! Thanks for your help
    Ron

  • Using the EXTRACT function to get year and month from date

    Hello~
    I am trying to extract the month and year using the query below but am getting the error:
    Query cannot be parsed within the Builder
    select     distinct city AS "CITY",count(MOTOR_ASSIST2.CITY) as "COUNT"
    from     "MOTOR_ASSIST2" "MOTOR_ASSIST2"
    where
    (:P53_FISCAL_YR IS NULL OR :P53_FISCAL_YR = MOTOR_ASSIST2.FY)
    *OR (:P53_MONTH IS NULL OR EXTRACT(MONTH FROM :P53_MONTH) = MOTOR_ASSIST2.DATETIME)
    OR (:P53_YEAR IS NULL OR EXTRACT(YEAR FROM :P53_YEAR) = MOTOR_ASSIST2.DATETIME))*
    GROUP BY MOTOR_ASSIST2.CITY
    ORDER BY CITY
    Can anyone help me figure out what im doing wrong?Thanks
    Deanna

    1. Whats the value of year you are passing here ??
    2. Whats the value of months you are passing here??
    Select City As "CITY", Count(Motor_Assist2.City) As "COUNT"
      From "MOTOR_ASSIST2" "MOTOR_ASSIST2"
    Where ((:P53_Fiscal_Yr Is Null Or :P53_Fiscal_Yr = Motor_Assist2.Fy) Or
           (:P53_Month Is Not Null Or :P53_Month = Motor_Assist2.Month) And
           (:P53_Year Is Not Null Or :P53_Year = Motor_Assist2.Year) And
           Datetime >= To_Date(:P53_Year||:P53_Month, 'YYYYMON') And
           Datetime > Add_Months(To_Date(:P53_Year||:P53_Month, 'YYYYMON'), 1)
    Group By Motor_Assist2.City
    Order By City
    SQL> Select Sysdate From dual Where Sysdate = To_Date('2008'||'SEP', 'YYYYMON');
    SYSDATE
    Select Sysdate From dual Where Sysdate = To_Date('2008'||'SEP', 'YYYYMON');
    SYSDATE
    SQL> Select To_Date('2008'||'SEP', 'YYYYMON') From dual;
    TO_DATE('2008'||'SEP','YYYYMON
    9/1/2008
    will give you sept 1st or 1st day of the month,
    hows the data in your datetime column or variable ???
    SQL> Select Sysdate From dual Where trunc(add_months(last_day(Sysdate),-1) +1) = To_Date('2008'||'SEP', 'YYYYMON');
    SYSDATE
    9/12/2008 3
    SQL>
    there both side of '=' yield first day of sept ...
    SQL>

  • 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

  • FM to get previous fiscal month/year and calendar month/year for a date.

    Hi All,
    I am having a requirement to extract some data based on either the previous fiscal month/year or the previous calendar month/year. There is no company code input to find the fiscal/calendar month/year.
    At selection screen, user can select either fiscal or calendar selection.
    Based on the selection, the data will be extracted.
    For the system date, we need to calculate previous fiscal month/year or previous calendar month/year and populate the calculated data back to the selection-screen.
    Can you one of you please suggest an FM to find previous fiscal month/year and previous calendar month/year.
    Thanks in Advance,
    Regards
    Gowthami

    Hi Gowthami,
    You can use following function module to calculate previous / next day or month or year.
       call function '/SAPHT/DRM_CALC_DATE'
          exporting
            date      = sy-datum
            days      =
            months    =
            sign      = '-'
            years     =
          importing
            calc_date = .
    Here, you can give '-' to sign, if you want previous day / month / year.
    Here, you can give '+' to sign, if you want next day / month / year.
    And depending upon your requirement, you can pass suitable value to days / month / year.
    e.g. To calcualte last month,
       call function '/SAPHT/DRM_CALC_DATE'
          exporting
            date      = sy-datum
            days      =
            months    = 1
            sign      = '-'
            years     =
          importing
            calc_date = wv_prev_month.
    so it will give '23-01-2008' . Then convert it in the required format as per your requirement using string function concatenate.
    Hope this help you.
    Regards,
    Anil

  • How to extract year alone form a given date

    Hi all,
    How to extract year from a given date alone.
    eg: 01/01/2000.
    i want 2000 separately. How can i do that?
    Plz help me regarding this.
    Thanks & Regards,
    vineel

    Hi Vineel,
    You can use the first four chars of the date field..
    w_year = w_date(4)
    Else, you can use the FM:
    GET_CURRENT_YEAR
    Thanks and Best Regards,
    Vikas Bittera.
    **Reward if useful**

  • 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

  • Field Date year and month

    Hi, 
    I'd like to get only year and month field. E.g. 201409.
    Could you please let me know how to do it?
    ddwrt:FormatDate(ddwrt:Today(),0804,1)
    Thank you. 

    Hi Denis - Can you use like:
    formatted date "=TEXT(pickdate,"m") & "/" & YEAR(pickdate)"
    http://weekbeforenext-blog.blogspot.in/2011/06/extracting-month-and-year-from-date-and.html
    -prs

Maybe you are looking for