Getting previous month

could you please tell me how to get previous month?
using sysdate gives me current date. from that i can get current month using to_char function. But how can I get the previous month?

All you ned to remember is that there are two date units, days and months. Everything else is a multiple/fraction of these.
To increment
n days:    SYSDATE + n
n hours:   SYSDATE + n/24
n minutes: SYSDATE + n/24/60
n seconds: SYSDATE + n/24/60/60
n weeks:   SYSDATE + n*7
n months:  ADD_MONTHS(SYSDATE,n)
n years:   ADD_MONTHS(SYSDATE,12*n)

Similar Messages

  • How to Get Previous Month Salary for a particular employee?

    Hi
    I am developing a report to get the Net Pay Difference from Previous month.
    I am using logical database pnp.
    My question is how can we get the last month (Previous from current selected month) salary of perticular employee. I read the thread which is related to this but I can't understand the reply's. I think it is due to that I am new in ABAP and my experience in only 22 days. If someone reply with code example then it will more helpful for me.
    Also If you can tell me the table name from where we can get the salary of particular month of particular employee then it will also helpful for me.
    Regards
    Iftikhar

    Hi,
    Payroll data is stored in cluster tables.
    You can either use macro for retrieving the data or Function module.
    1. Use FM -CU_READ_RGDIR for getting the RG directory values.Pass  
      employee Number and molga.You will get all the sequence Numbers from this
      FM.
        The last record will be the latest  one.
    2.  Then Use FM - PYXX_READ_PAYROLL_RESULT for getting the payroll  
         results table.Pass cluster ID- 'IN'  ,pernr ,sequence number for which period
          you want (In your case ,current period minus   1) and
          READ_ONLY_INTERNATIONAL            = 'X',
    3. You will get all the results from PAYROLL_RESULT                     = it_result
      Then you can loop this internal table like LOOP at it_result-inter-rt into wa..
    Get the net pay value(/560 wage type)
    Reward points if helpful.
    Regards,
    Manoj.

  • How to get previous month data from current month values

    Hi Experts,
    I have made one universe from BW Query in which Fiscal year period is entered in interval.
    I have made a universe from that and want to develop webI reports on top of that.
    In my webI reports, i have used one cross tab. In Rows section i have added Company Code and in Column section i have used Fiscal Year/Period and in Value section i have added Sales Value. I want this value of previous month.
    Requirement:
    Ex.
                            Feb'09          Mar'09     and so on...
    Comp_code1   Sales of Jan'09         Sales of Feb'0f         and so on....
    I am getting this.
    Ex.
                            Feb'09          Mar'09     and so on...
    Comp_code1   Sales of Feb'09         Sales of Mar'09         and so on....
    I hope i have clear my requirements.
    Please help as soon as possible.
    Thanks in Advance,
    Rishit

    Hi Rishit,
    Follow the below steps to get the desired result.
    Step1: Convert your fiscal year period from char to a date in your database or in your designer however its feasible.
    to_date('substr('009.2009',2)','mm.yyyy')
    you will get the result 01 sep 2009
    Step2: Convert this format to 01/09/2009 by using date functions.
    Step3: Create a Detail associated to the 'date' field (typically your fiscal period).
    Step4: Create a cross tab Like : Rows section should have Company Code and in Column section should have 'date'(created detail) and in Value section should be Sales Value.
    you should get the following result.
    01/02/2009 01/03/2009 and so on...
    Comp_code1 Sales of Feb'09 Sales of Mar'09 and so on....
    Step5: Use the following formula in your Column (date) formula bar.
    =(<date>-1)-DayNumberOfMonth(<date>-1)+1
    You will get the following result:
    01/01/2009 01/02/2009 and so on...
    Comp_code1 Sales of Feb'09 Sales of Mar'09 and so on....
    Format the cell according to your reruirement.
    Let me know if you will get any break in the above steps.
    Regards,
    Swati.

  • Which SQL function to use to get previous month's data?

    Hi
    The reporting need: Display of two month's payroll run results....current and previous (based on the parameter passed) in Oracle Discoverer.
    Data source: A table in which run result values are stored. Of course to be linked to number of other tables.
    Can somebody guide me on which SQL function to use to get the data for previous month?
    Secondly, as Discoverer does not support parameters, I cannot put parameter in the query itself. I'll be applying parameter later while generating my report.
    Please advice.
    Thanks and regards,
    Aparna

    It's not very clear in my head... but you can try :
    SQL> select * from test;
    ENAM        SAL DT
    TOTO       1000 30/05/06
    TOTO       1001 20/04/06
    TOTO       1002 11/03/06
    TATA       2000 30/05/06
    TATA       1500 20/04/06
    TUTU       3500 30/05/06
    6 rows selected.
    SQL> select ename, dt, sal currmonth,
                case when trunc(lag(dt,1,dt) over (partition by ename order by dt),'MM') = trunc(add_months(dt,-1),'MM')
                     then lag(sal,1,sal) over (partition by ename order by dt)
                     else null end prevmonth
         from   test
    SQL> /
    ENAM DT        CURRMONTH  PREVMONTH
    TATA 20/04/06       1500
    TATA 30/05/06       2000       1500
    TOTO 11/03/06       1002
    TOTO 20/04/06       1001       1002
    TOTO 30/05/06       1000       1001
    TUTU 30/05/06       3500
    6 rows selected.
    SQL>
    SQL> Nicolas.
    Just an additional question : do the previous month is current month-1, or is there hole in month suite (e.g. the previous month can be current month-2) ?
    Message was edited by:
    N. Gasparotto

  • Use a filter to get previous months results

    Hello,
    I want to put a filter on a new report that will only pull information from the last month. I know I can use a timestamp calculation to get 30 days back...but this will pull info 30 days back from when the report is run.
    I want one that will pull Octobers info if run anytime in November, for example.
    The filter will be on the "created date" field.
    Thanks!

    Hi,
    I am facing a similar issue.
    In the report, I have 3 columns to display data for -> Current Month, Current Month - 1 & Current Month - 2.
    The formula that I am using is something like this:
    CASE WHEN (Condition A AND Condition B) THEN (Expression X) ELSE (Expression Y) END
    Here the Condition B is:
    MONTH(Activity."Planned Start Time") = (MONTH(CURRENT_DATE)) for the Current Month
    MONTH(Activity."Planned Start Time") = (MONTH(CURRENT_DATE)-1) for the Previous Month &
    MONTH(Activity."Planned Start Time") = (MONTH(CURRENT_DATE)-2) for Previous to Previous Month
    This works ok for months from March to Dec, however for Jan and Feb, the data for Nov & Dec is not visible.
    How can I remedy this? Is there any variable to represent LAST_MONTH?
    (I tried to used embedded CASE statement to check the condition that if (for Current Month - 1), Month = 1, then Start Time = 12 & Year = Year(current_date) -1 , but that did not work.)
    Ady

  • To get previous month's data

    Hi
    My report requirement:
    Display current month and previous month's data (sal) next to each other based on the month selected as a current month.
    Expression I'm using at the moment:
    case when trunc(lag(dt,1,dt) over (partition by ename order by dt),'MM') = trunc(add_months(dt,-1),'MM')
    then lag(sal,1,sal) over (partition by ename order by dt)
    However, instead of 'dt' I'm trying to use a parameter (dt as a current month's dt).
    This gives me an error message.
    Can anyone guide me on this?
    Thanks and regards,
    Aparna

    Why not simply join the table with itself? I.e. join the two months data sets and have a single row containing current and previous month results
    Simplistic example. We have a YEARLY_TOTALS table where the primary key is MONTH in the date format YYYY/MM. You can then compare the sales totals per month of this year with that of last year using the following type of SELECT construct:
    SELECT
    cur.month,
    cur.sales as CURRENT_SALES,
    prev.sales as LAST_YEAR_SALES
    FROM yearly_totals cur
    JOIN yearly_totals prev
    ON ADD_MONTHS(prev.month,12) = cur.month
    WHERE cur.month >= TRUNC(SYSDATE,'YY')

  • How to get previous month's values for current month

    Hi..
    I have a requirement on a report, where for a particular month, the key figure value should be from the previous month.
    Eg: KF1 value for Sept 2007 should come from Aug 2007, KF value for Dec 2007 should be the value of Nov 2007, etc.
    There are other key figures on the report which do not need this logic. It is only for one key figure.
    Should we do this on the backend or front-end, and how? Any tips will be appreciated.
    Thanks
    R.

    hi,
    Use a Restricted Keyfigure.
    Drag your KF1 and Drag Calandar Month with a Variable Current Cal Month with variable Offset to -1.
    KEERTTHi

  • Previous month first data and previous month last date

    can any body have query to get previous month first date and previous month last date.
    Ex: First day of the previous week:
    TIMESTAMPADD(SQL_TSI_DAY,-6, (TIMESTAMPADD(SQL_TSI_DAY, DAYOFWEEK(CURRENT_DATE) *-1,CURRENT_DATE)))
    Last day of the previous week:
    TIMESTAMPADD(SQL_TSI_DAY, DAYOFWEEK(CURRENT_DATE) *-1,CURRENT_DATE)
    can anybody have it for first day of the previous month,last day of the previous month?
    Edited by: user12255470 on Apr 7, 2010 3:30 AM

    Hi,
    1st day of previous month :
    TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(TIMESTAMPADD(SQL_TSI_MONTH,-1,CURRENT_DATE)) * -1) + 1, TIMESTAMPADD(SQL_TSI_MONTH,-1,CURRENT_DATE))
    last day of previous month :
    TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(TIMESTAMPADD(SQL_TSI_MONTH,-1,CURRENT_DATE)) * -1 , TIMESTAMPADD(SQL_TSI_MONTH, 1, TIMESTAMPADD(SQL_TSI_MONTH,-1,CURRENT_DATE)))
    Please mark Q answered and award points for correct answers !
    Thanks
    Alastair

  • To retrive previous month based on month prompt

    Hi,
    My universe is based on SAP BEX query. I have a requirement to report the previous month data based on a month prompt. Since the universe is based on the MDX, could anyone suggest a way to calculate previous month from universe.
    Appreciate your responses.
    Regards,
    VyshBO

    pvinesh wrote:
    Hi VyshBO,
    >
    > You can refer below syntax and prepare a filter object in universe to get Previous Month.
    >
    >
    <FILTER KEY="[ZMONTH].[LEVEL01].[[ZMONTH]].[Value]"><CONDITION OPERATORCONDITION="Equal"><CONSTANT CAPTION="-1"/></CONDITION></FILTER>
    >
    >
    > Regards,
    > Vinesh
    Can  you explain that syntax, Vinesh? In particular, what does the [[ZMONTH]] imply?

  • Problem in measure for previous month

    i have columns like following
    d_name Value
    JAN-11 4586236
    FEB-11 2121512
    MAR-11 32121
    APR-11 12121
    p_name is varchar2 type
    Now i need value for previous month can u do it without using queries or obiee
    I am unable to build hierarchy cause of its type. any suggesions

    You might have month numbers in rpd, use ago function to get previous month value

  • How to get the last day of the previous month

    Hello Team,
    If  my input date is today , then i need to find out the last day of the previous month for the same.
    Can someone help me  to find out .. how can this be done.
    Regards,
    Ravi

    Hi,
    Try the below code.
         // get a calendar object
        GregorianCalendar calendar = new GregorianCalendar();
        // convert the year and month to integers
        int yearInt = Integer.parseInt(year);
        int monthInt = Integer.parseInt(month);
         int dayInt = Integer.parseInt(day);
        // adjust the month for a zero based index
        monthInt = monthInt - 1;
        // set the date of the calendar to the date provided
        calendar.set(yearInt, monthInt, dayInt);
        int day = calendar.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
        return Integer.toString(day);
    Regards
    Venkat

  • TS4036 I added Icloud to join my calendar to another person. It erased all history date from previous months. how do I get that data back?

    I added Icloud to join my calendar on my phone to another person. It erased all history date from previous months. how do I get that data back?

    i found the answer to the first part: reboot and keep hold of command+r
    this gave me a list of options
    one of them was to reinstall lion from fresh
    i went for this
    dont know why... but all forum posts i read said u should delete hard disc? theres an option for this
    which is the right option?
    any suggesstion where i go to register new mac would be great
    thanks

  • How to get Last Day of a Previous Month

    Hi all,
    I need to get Last Day of the Previous Month. I am able to get Current Month Last Day using Calendar.getActualMaximum(Calendar.DATE)
    But I need previous Month's Last Day.
    Thanks
    Vamshi.

    Thanks all....
    I have been trying the same and could get it.....
    here is the code for that....
    SimpleDateFormat simpleDate = new SimpleDateFormat("MM/dd/yyyy");
    Calendar calendar = Calendar.getInstance();
    month = calendar.get(Calendar.MONTH);
    //year = calendar.get(Calendar.YEAR);
    calendar.set(Calendar.MONTH, month-1);
    calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
    //lastDayOfMonth = calendar.getActualMaximum(Calendar.DATE);
    System.out.Println("Previous Month End Date is :: " + simpleDate.format(calendar.getTime()));
    this works....
    thanks for ur replys....

  • Function module to get the same date of the previous month

    Hi
    Can anybody tell me how to get the
    same date of the previous month.
    example if i am entering date as 30 may 2007
    i want the date as 30 april 2007

    CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
    EXPORTING
    date = pa_end
    days = '00'
    months = '01'
    signum = '-'
    years = '00'
    IMPORTING
    calc_date = pa_end.
    ENDIF.
    nd try below FMs as well...
    CCM_GO_BACK_MONTHS
    HR_PT_ADD_MONTH_TO_DATE
    RP_CALC_DATE_IN_INTERVAL
    Hope it will solve your problem...
    Reward points if useful..
    Thanks & Regards
    ilesh 24x7

  • MDX dimension formula in BPC to get the previous month failed with parents

    Hi,
    I'm working on a proof of concept and I need to create a formula with the following requirement:
    Requirement               
    Account2 = Account2 (Previous Month) + Account 1               
    Accounts -Jan-Feb-Mar-Q1
    Account1_____15___25___45____85
    Account2_____15___40___85___140     <== OK
    Now, I was thinking of applying this formula within Dimension, using MDX. Then I tried with these two examples, but they didn't work when rolling up to parents. I mean, the calculation for every month works fine, but, the Total Quarter or the Total Year are wrong:
    Attempt 1:
    Account2.Formula = (ParallelPeriod([Time].[Month], 1, [Time].CurrentMember), Account2) + Account1
    Accounts -Jan-Feb-Mar-Q1
    Account1_____15___25___45____85
    Account2_____15___40___85____85     <== WRONG
    Attempt 2:
    Account2.Formula = (Account2,[Time].PrevMember) + Account1
    Accounts -Jan-Feb-Mar-Q1
    Account1_____15___25___45____85
    Account2_____15___40___85____85     <== WRONG
    How can I solve this ? Should I use Script logic instead of MDX to perform this calculation ?
    Thanks!
    Diego.

    DON'T use MDX script logic.  It does not perform well under high data volumes or concurrency.
    You're calculation can be done easy enough in SQL logic provided you scope the code correctly.  Based on what you have given as requirements, the basic code would be something like:
    *XDIM_ADDMEMBERSET TIME = PRIOR
    *XDIM_ADDMEMBERSET ACCOUNT=A2
    *WHEN ACCOUNT
    *IS "A1"
        *REC(EXPRESSION=%VALUE%+GET(ACCOUNT="A2",TIME=PRIOR),ACCOUNT=A2)
    *ENDWHEN
    *COMMIT
    The first two lines make sure you have the prior period values for A2 in the scope of exection.  Then when a record for A1 comes through, it would take that value and add it to A2's prior value for the exact same intersection of all other dimensions.  You would separately have to deal with moving forward values of A2 if there were cases where you could have a value for A2 in a prior period but not have a value in A1 for the current period.
    Edited by: James Sharrett on Apr 14, 2008 9:51 AM

Maybe you are looking for