CONVERT   DATE RANGE INTO MONTHS

HI FRIENDS,
ACTUALLY IN MY SELECT-OPTIONS I HAVE USED DATE BETWEEN 03/06/1980  TO 04/12/1980
BASED ON THIS DATE I HAVE TO CALCULATE NUMBER OF MONTHS.
WILL THIS BE DONE AUTOMATICALLY OR I NEED TO WRITE ANY CODE FOR CONVERTING THE DATE RANGE INTO NUMBER OF MONTHS.
REGARDS
SIRI.

Hi,
Use FM's : MONTHS_BETWEEN_TWO_DATES_NEW
           MONTHS_BETWEEN_TWO_DATES
           FIMA_DAYS_AND_MONTHS_AND_YEARS
Sample code :
DATA : x_no_months type i.
DATA : x_stdat like sy-datum,
       x_enddat like sy-datum.
       x_stdat  = s_date-low
       x_enddat = s_date-high
CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
    EXPORTING
      i_datum_bis = x_stdat
      i_datum_von = x_enddat
    IMPORTING
      e_monate    = x_no_months.
x_no_months will contain no.of months.
Regards
Appana

Similar Messages

  • Need work around to split date range into months

    Hi All,
    I have a requirement to split the data range in source table to months.
    here is the source table
    ID Sdate Edate Code
    ===============================
    501 1/4/2009 4/30/2009 AH
    501 5/1/2009 9/30/2009 AB
    502 1/1/2014 5/31/2014 AC
    Here is my target
    ID Sdate Edate Code
    ================================
    501 1/4/2009 1/31/2009 AH
    501 2/1/2009 2/28/2009 AH
    501 3/1/2009 3/31/2009 AH
    501 4/1/2009 4/30/2009 AH
    501 5/1/2009 5/31/2009 AB
    501 6/1/2009 6/30/2009 AB
    501 7/1/2009 7/31/2009 AB
    501 8/1/2009 8/31/2009 AB
    501 9/1/2009 9/30/2009 AB
    502 1/1/2014 1/31/2014 AC
    502 2/1/2014 2/28/2014 AC
    502 3/1/2014 3/31/2014 AC
    502 4/1/2014 4/30/2014 AC
    502 5/1/2014 5/31/2014 AC
    Please provide some input.
    Thanks a lot in advance.

    That means your database is in a different locale than mine. When I select cast(Edate as varchar), I get the date returned in the format 'YYYY-MM-DD'. That's why I use(left(cast(Edate as varchar),4) + right(left(cast(Edate as varchar),7),2) to get it the format 'YYYYMM' before converting it into an integer.
    Your database most probably returns dates in a format like D/MM/YYYY. That's the reason for the error you get. You'll have to select (right(cast(Edate as varchar),4) + left(right(cast(Edate as varchar),7),2) to obtain the same results as I do.
    Alternatively, you can use the convert function to obtain the same results:
         select max(
         cast(left(convert(varchar,Edate,102),4) + right(left(convert(varchar,Edate,102),7),2) as int) + 1 -
         cast(left(convert(varchar,Sdate,102),4) + right(left(convert(varchar,Sdate,102),7),2) as int))
         FROM src_split'
    It's always good practice to test the SQL-statements in your database client first before including them in a DS script.
    Also, I suddenly realise this statement will only return the correct result when your Edate and Sdate are always within the same year. If that's not the case, but the gap between Edate and Sdate is always less than 10 years, change your statement to:
         select max(
         cast(left(convert(varchar,Edate,102),4) + right(left(convert(varchar,Edate,102),7),2) as int) + 1 -
         cast(left(convert(varchar,Sdate,102),4) + right(left(convert(varchar,Sdate,102),7),2) as int)) % 88
         FROM src_split'

  • How to convert Date format into day in ssrs reports?

    Hi
    How to convert date format into day?
    10/01/2010 as like Monday like that?

    =weekdayname(datepart("w",Fields!mydate.Value))
    -Vaibhav Chaudhari

  • FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.

    HI EXPERTS,
         FUNCTION MODULE TO CONVERT DATE / TIME INTO WORDS.
    PLS DO HELP.....

    Hiii gita
    we have another FM SPELL_AMOUNT
    regards
    Jaipal

  • How to drill date (column )into month in xcelsius

    Hi,
    I am fresher to Xcelsius. I need to know how to drill the date column into month, then further drilling down month to day.
    I have 2 columns
    Date                       Revenue
    1/1/2010                 452553
    2/2/2011                  97992
    3/5/2011                  23526
    4/3/2011                 63563
    If i click " 1/1/2011" date column, i need to see the corresponding month data in seperate chart( i need to get the detailed data).
    I need to know how the datas should be arranged in excel.
    Thanks in Advance
    Regards,
    Abirami

    Hi Abirami,
    To filter out date, you can use calendar component in Xcelsius. This article explains how to use the calendar component in an interactive way.
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/b05b0244-0453-2e10-b4b3-fab707baddaf
    Then with the help of an invisible combo box as explained in the article to could get just the selected month's data in bar chart.
    Hope this helps.
    Regards,
    Anju Saseendran

  • Convert date format from MONTH-YEAR to  dd/mm/yyyy

    Dear All
    i want to get parameter in form of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE.
    SELECT
    TO_CHAR (PTP.END_DATE,'MONTH-YY') ,
    to_date ( TO_CHAR (PTP.END_DATE ,'DD-MONTH-YYYY') ,'dd/mm/yyyy'),
    --- i want to gent parameter in from of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE
    to_date ( TO_CHAR (PTP.END_DATE ,'MONTH-YYYY') ,'dd/mm/yyyy'),
    ADD_MONTHS((to_date ( TO_CHAR (PTP.END_DATE ,'MONTH-YYYY') ,'dd/mm/yyyy'),-1)
    --- i want to gent parameter in from of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE
    ptp.END_DATE PERRIODS_NAME
    from per_time_periods ptp
    Regards
    Edited by: user10941925 on Nov 28, 2011 12:23 AM

    Hello just check
    SQL> select hiredate from emp;
    HIREDATE
    17-DEC-80
    20-FEB-81
    22-FEB-81
    02-APR-81
    28-SEP-81
    01-MAY-81
    09-JUN-81
    09-DEC-82
    17-NOV-81
    08-SEP-81
    12-JAN-83
    03-DEC-81
    03-DEC-81
    23-JAN-82
    14 rows selected.
    SQL> select to_char(hiredate,'month-year') from emp;
    TO_CHAR(HIREDATE,'MONTH-YEAR')
    december -nineteen eighty
    february -nineteen eighty-one
    february -nineteen eighty-one
    april    -nineteen eighty-one
    september-nineteen eighty-one
    may      -nineteen eighty-one
    june     -nineteen eighty-one
    december -nineteen eighty-two
    november -nineteen eighty-one
    september-nineteen eighty-one
    january  -nineteen eighty-three
    december -nineteen eighty-one
    december -nineteen eighty-one
    january  -nineteen eighty-two
    14 rows selected.
    SQL> select to_char(hiredate,'dd/mm/yyyy') from emp;
    TO_CHAR(HI
    17/12/1980
    20/02/1981
    22/02/1981
    02/04/1981
    28/09/1981
    01/05/1981
    09/06/1981
    09/12/1982
    17/11/1981
    08/09/1981
    12/01/1983
    03/12/1981
    03/12/1981
    23/01/1982
    14 rows selected.
    SQL>

  • Spliting user entered date range into u201CFrom Date u201C and u201C To dateu201D-user exit

    Hi,
    In the query i have a created a popup variable for date range for which the processing type is customer exit. When the user exceutes the query he gets the popup for the date range with the default values. The default values are set one month backward.
    For example: if today is 5/19/2008, then the popup date range shows 4/19/2008 to 5/19/2008.
    Already there is an user exit written for the same.
    Now the requirement is i need to split From date and to date entered by user and use them in seperate selections to restrict the keyfigure in the keyfigure column of the query.
    Can anyone throw a light on this, how to go about?
    Shall i need to create two different variables from date and two date and populate the values, if yes how can i do that ?
    Thanks,
    Rani.
    Edited by: rani on May 19, 2008 10:22 AM

    Hello Rani,
                     Check this code,
    var1 is already existing variable with values from date and to date values.
    ztest1 is the first customer exit single variable,
    ztest2 is the second customer exit variable.
    ztest1 and ztest2 you can use these variables in the restricted keyfigures which you have mentioned.
    when 'ztest1'.
        if i_step = 2. "after the popup
          loop at i_t_var_range into loc_var_range
          where vnam = 'var1'.
            clear l_s_range.
            l_s_range-low = loc_var_range-low.
            l_s_range-sign = 'I'.
            l_s_range-opt = 'EQ'.
            append l_s_range to e_t_range.
            exit.
          endloop.
        endif.
    when 'ztest2'.
        if i_step = 2. "after the popup
          loop at i_t_var_range into loc_var_range
          where vnam = 'var1'.
            clear l_s_range.
            l_s_range-low = loc_var_range-high.
            l_s_range-sign = 'I'.
            l_s_range-opt = 'EQ'.
            append l_s_range to e_t_range.
            exit.
          endloop.
        endif.
    hope it helps,
    regards,
    karthik

  • Extracting a count of distinct values between two date ranges over months

    Hi All,
    I am having a bit of difficulty in figuring out the query to build a list of active campaigns over a date range.
    i.e. I have a table with campaign IDs and their start and end date details like this
    Campaign_id     Start_date     End_date
            10001     1-Jun-09     31-May-11
            10002     1-Jun-09     23-Jun-11
            30041     21-Aug-09     31-Dec-09
            20005     3-Jun-10     31-May-11
            90021     21-Nov-09     30-Nov-10
            54000     1-Jun-11     1-Dec-12
            35600     1-Mar-10     31-Mar-12 What the above data means is, for eg. the campaign 10001 is active from 1-Jun-09 to 31-May-11 i.e. for 24 months (inclusive of the month Jun-09 and May-11)
    What I need to figure out is the counts of active campaigns between a date range and display that active count at a month level (for e.g. lets say we want to see all the campaigns that were active
    between the date range '01-JUN-2007' and '30-APR-2012' ). So the partial output would be as seen below. The list would continue till december-2012
    Month    Year    Count of active campaigns
    Jan    2009    0
    Feb    2009    0
    Mar    2009    0
    Apr    2009    0
    May    2009    0
    Jun    2009    2
    Jul    2009    2
    Aug    2009    3
    Sep    2009    3
    Oct    2009    3
    Nov    2009    4
    Dec    2009    4
    Jan    2010    3
    Feb    2010    3
    Mar    2010    4
    Apr    2010    4
    Dec    2012    1 Could anybody please help me with the right query for this.
    Thanks a lot for help
    Regards
    Goldi

    set pagesize 40
    with tab as
                    select 1 id, sysdate -100 start_date, sysdate end_date from dual
                    union
                    select 1 id, sysdate -200 start_date, sysdate -150 end_date from dual
                    union
                    select 1 id, sysdate -600 start_date, sysdate - 400 end_date from dual
                    union
                    select 1 id, sysdate -300 start_date, sysdate - 150 end_date from dual
                    union
                    select 2 id, sysdate -100 start_date, sysdate-50 end_date from dual
          year_tab as
                        select
                                 add_months(min_date, level -1) m
                        from
                                select min(trunc(start_date,'YYYY')) min_date, add_months(max(trunc(end_date,'YYYY')), 12) max_date
                                from tab
                        connect by level <= months_between(max_date, min_date)
    select to_char(m,'YYYY') year_,
             to_char(m,'Month') month_,
             nvl(act, 0) act
    from   year_tab,
                select m date_,count(*)  act
                from tab, year_tab
                where m between trunc(start_date,'MM') and trunc(end_date,'MM')
                group by m
                ) month_tab
    where m = date_(+)
    order by m;
    YEAR_ MONTH_           ACT
    2010  January            0
    2010  February           0
    2010  March              0
    2010  April              0
    2010  May                0
    2010  June               0
    2010  July               0
    2010  August             0
    2010  September          1
    2010  October            1
    2010  November           1
    2010  December           1
    2011  January            1
    2011  February           1
    2011  March              1
    2011  April              0
    2011  May                0
    2011  June               0
    2011  July               1
    2011  August             1
    2011  September          1
    2011  October            2
    2011  November           2
    2011  December           2
    2012  January            2
    2012  February           2
    2012  March              2
    2012  April              1
    2012  May                1
    2012  June               0
    2012  July               0
    2012  August             0
    2012  September          0
    2012  October            0
    2012  November           0
    2012  December           0
    36 rows selected.

  • Opendoc date range into Bex query

    We are having an issue when trying to pass a date range in an Opendoc link. The report is built off a BEx query,  within the report we have an Opendoc link into a child version of the report. I can pass all the other prompts with no issue except for one which is the date range.
    I am defining the date range as "[19000101]..[19000101]" but we keep getting this error message:
    Has anyone lese had this issue?
    Thanks

    Hi,
    Try This
    "[Date(2014,04,01)]..[Date(2014,04,11)]"
    "[Date(yyyy,MM,dd)]..[Date(yyyy,MM,dd)]"
    http://help.sap.com/businessobject/product_guides/boexir4/en/xi4_opendocument_en.pdf#page=26
    http://<servername>:<port>/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=Aa6GrrM79cRAmaOSMGoadKI&sID
    Type=CUID&sRefresh=Y&lsRTime+Period:=[2000..2004)
    http://<servername>:<port>/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=Aa6GrrM79cRAmaOSMGoadKI&sID
    Type=CUID&sRefresh=Y&lsRparamStringDR=[h..i]&lsRparamNumberDR=[7..8]&lsRparamCurrencyDR=[3..4]&lsRparamDat
    eDR=[Date(2003,6,7)..Date(2003,6,8)]&lsRparamDateTimeDR=[DateTime(2003,6,1,7,1,1)..Date
    Time(2003,6,1,8,1,1)]&lsRparamTimeDR=[Time(1,1,7)..Time(1,1,8)]&lsRparamUnbound1=(..6)&lsRpara
    mUnbound2=[6..)&lsRparamStringR=[a..d]&lsRparamNumberR=[1..3]&lsRparamCurrencyR=[1..3]&lsRparam

  • How to convert date format into sap standard format?

    Hi All,
    In SAPUI5 screen i have one simple form in form i have date field which is format  (MM/DD/YYYY). but i am getting POST error while inserting the data in to sap table.
    I want convert date format in sap format (YYYY/MM/DD).
    One more issue, when i am fetching the data from sap table,but  the date display with time and time zone.
    eg. Sat Aug 02 2014 05:30:00 GMT+0530 (India Standard Time)
    I want to display only date.
    Thanks,
    Prashant.

    Now i am using <DatePicker id="Emp_fsdate" displayFormat="yyyy-MM-dd"/>
    I checked in console, but date is display like mm/dd/yy
    In my controller.js file i have written code
    OData.request
               requestUri: "http:sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata", 
               method: "GET",
               headers:
               "X-Requested-With": "XMLHttpRequest",
               "Content-Type": "application/atom+xml",
               "DataServiceVersion": "2.0",       
               "X-CSRF-Token":"Fetch"
           function (data, response){
            var header_xcsrf_token = response.headers['x-csrf-token'];
                       OData.request
                            requestUri:
                             "http://sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata", 
                            method: "POST",
                            headers:
                          "X-Requested-With": "XMLHttpRequest",                     
                            "Content-Type": "application/atom+xml",
                            "DataServiceVersion": "2.0",
                            "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
                            "X-CSRF-Token": header_xcsrf_token
                            data:
                                   Empid:Emp_id,
                                   Empname:Emp_name,
                                   Start_Date:Emp_sdate,
    //                              End_Date:Emp_edate,
                                   Status:Emp_status,
                                   City:Emp_city,
                                   Location:Emp_location,
    and in my CREATE_ENTITY method
    method ES_SODATA_CREATE_ENTITY.
         DATA: ls_request_input_data TYPE zcl_zservice_final_mpc=>ts_et_sodata,
             ls_userinfo TYPE zsodata.
       DATA ls_temp TYPE sy-datum.
    * Read Request Data
       io_data_provider->read_entry_data( IMPORTING es_data = ls_request_input_data ).
    * Fill workarea to be inserted
       ls_userinfo-Empid   = ls_request_input_data-Empid.
       ls_userinfo-Empname   = ls_request_input_data-Empname.
       ls_userinfo-Start_Date   = ls_request_input_data-Start_Date.
       ls_userinfo-End_Date   = ls_request_input_data-End_Date.
       ls_userinfo-Status   = ls_request_input_data-Status.
       ls_userinfo-City   = ls_request_input_data-City.
       ls_userinfo-Location   = ls_request_input_data-Location.
    * Insert Data in table ZUSERINFO
       INSERT zsodata FROM ls_userinfo.
       IF sy-subrc = 0.
         er_entity = ls_request_input_data. "Fill Exporting parameter ER_ENTITY
       ENDIF.
       endmethod.
    But still i am getting an error
    POST http://sap/opu/odata/sap/ZSERVICE_FINAL_SRV/es_sodata 500 (Internal Server Error)
    I am able to insert all field except date field. How to insert date field in sap table.

  • Function Module for separating a date range into days

    Hi all,
    Does anyone know if there is a function module which gives back the list of days when we give a date range as input parameter to the function module. For example, we enter the range 10.07.2006 - 13.07.2006 and the function module gives back a table  in form 10.07.2006, 11.07.2006, 12.07.2006, 13.07.2006.
    Thanks,
    Sükrü

    Hi suekrue,
    1. Exactly for this purpose,
       i have written an
       INDEPENDENT FORM (subroutine)
      wherein we pass
       a) fromdate
       b) todate
       c) ITAB
    2. and it gives all the dates in the internal table.
    3. just copy paste
    4.
    data :  itab type table of sy-datum with header line.
    parameters : fromdate type sy-datum default '20060701'.
    parameters : todate type sy-datum default sy-datum.
    perform getdays tables itab using fromdate todate.
    break-point.
    FORM
    form getdays
    tables itab
    using fromdate todate.
      data : curdate type sy-datum.
      curdate = fromdate.
      do.
        if curdate > todate.
          exit.
        endif.
        itab = curdate.
        append itab.
        curdate =  curdate + 1.
      enddo.
    endform.                    "getdays
    regards,
    amit m.

  • Converting the DATE(yyyymmdd) into MONTH(yyyymm) format

    HAI
    I have one date InfoObject(ZDATE) in the format of YYYYMMDD format.
    My client wants another 'Month InfoObject(ZMONTH) in the format of YYYYMM . This ZMONTH infoobject should be derived from ZDATE.
    So please tell me how can i convert the ZDATE data into ZMONTH format.
    I think , it is possible by writing the ABAP code.
    Please give the ABAP CODE for converting the ZDATE data into ZMONTH format also .
    i wll assing the points
    bye
    rizwan

    Hi Rizwan,
    You can use offset like:
    zmonth = zdate+0(6)
    Zmonth is variable in which yyyymm is going to be stored
    and zdate is variable in which yyyymmdd is stored.
    I think this will slove your issue.
    Thanks=points

  • SSRS Bar Chart grouping date series into Months, setting scaler start and end ranges

    I've been trying to solve this issue for a few days now without writing a sql script to create a "blank" for all of missing data points so that I get a bar for each month.  I have date series (by day) data points grouped by two items
    that creates a set of bar charts.  EG:  one chart per product in the tablix detail grouped to site level.
    My issue is I would like the start and end of the charts to be the same for all charts and the only way I get it to work is with a chart that continues to show each date on the chart. 
    EG:
    I have the graph start and end points set and scaling by month as I would like but each bar is a day instead of aggregating to a month level.   My issue I hope to find a workaround for is if I go to Category Groups and define the grouping
    to group with a year and month function the series is no longer treated as date data and I cannot control scaling.  It works fine if all months have activity, but I can't figure out how to always have all charts start at "May 2012" in this example. 
    The only start and end point that I've been able to get to work once doing this are integer based, eg normal start would be 1 for each graph, but 1 doesn't equate to the same month from chart to chart.
    I hope SSRS can provide the solution.  I do know I can write a query that creates a ZERO value for each month/product/site but I don't want to leave the client with a query like that to support.
    -cybertosis

    Hi cybertosis,
    If I understand correctly, you want to display all month category label in the X-Axis. You have configure the Scalar Axis, however, it cannot display the requirement format.
    In your case, if we want the specific data format, we can configure Number property to set the corresponding Category data format. Please refer to the following steps:
    Right click the X-Axis, select Horizontal Axis Properties.
    Click Number in the left pane. Click Date option in the Category dialog box.
    Then, select Jan 2000 option.
    Please refer to the following screenshot below:
    If there are any misunderstanding, please feel free to let me know.
    Regards,
    Alisa Tang
    If you have any feedback on our support, please click
    here.
    Alisa Tang
    TechNet Community Support

  • Converting Date Strings to Months

    I need to know how I can convert a Date String to a Month.
    For example, my Date String is 2/19/09, I need this converted to return February.   I need one formula which will take in account for all months.
    I am currently using the following to convert to a date, but I'm not sure how to then convert this to return a month... January - December.
    CStr({?EndDate},"yyyy-MM-dd")
    Thank you in advance for your assistance.

    Thank you so much, this does give me the month.
    How can I use this to group my report by month and then under it by received date?
    For example...
    February
        2/1/09     Ticket information.....
        2/2/09     Ticket information.....
        2/18/09   Ticket information....
    March
        3/1/09     Ticket information.....
        3/2/09     Ticket information.....
        3/18/09   Ticket information....
    And so on....
    Thanks again in advance.
    Edited by: Gary Timm on Feb 19, 2009 6:02 PM

  • Date ranges(5 months)

    Hi all...
      Iam having one date field in the selection screen....
    so when i excuted the program i have to get exact five months back date as low range and current date as high range...
    thank you,
    Naveen

    Hi Naveen
    try the following
    data : bk_date type sy-datum.
    select-options: so_date for sy-datum.
    INITIALIZATION.
      call function 'CCM_GO_BACK_MONTHS'
        exporting
          currdate   = sy-datum
          backmonths = 5
        importing
          newdate    = bk_date.
      clear so_date.
      so_date-sign   = 'I'.
      so_date-option = 'BT'.
      so_date-low    = bk_date.
      so_date-high   = sy-datum.
      append so_date.
    reward if useful.
    Regards
    Prabumanoharan

Maybe you are looking for