Previous month end date

hello,
i would like to find out the previous month end date when i give the input any date .
finding previous month end date.
eg :-> if i give the date as 02-Jan-2008, the result should be 31-dec-2007
if i give the input date as 10-nov-2007, the previous month end date is 31-Oct-2007
etc...

ME_XE?select the_date, trunc(the_date, 'MM') - 1 as las_day_prev_month
  2  from
  3  (
  4     select add_months(sysdate, level) as the_date from dual connect by level <=12
  5  );
THE_DATE                   LAS_DAY_PREV_MONTH
02-FEB-2008 08 58:30       31-JAN-2008 12 00:00
02-MAR-2008 08 58:30       29-FEB-2008 12 00:00
02-APR-2008 08 58:30       31-MAR-2008 12 00:00
02-MAY-2008 08 58:30       30-APR-2008 12 00:00
02-JUN-2008 08 58:30       31-MAY-2008 12 00:00
02-JUL-2008 08 58:30       30-JUN-2008 12 00:00
02-AUG-2008 08 58:30       31-JUL-2008 12 00:00
02-SEP-2008 08 58:30       31-AUG-2008 12 00:00
02-OCT-2008 08 58:30       30-SEP-2008 12 00:00
02-NOV-2008 08 58:30       31-OCT-2008 12 00:00
02-DEC-2008 08 58:30       30-NOV-2008 12 00:00
THE_DATE                   LAS_DAY_PREV_MONTH
02-JAN-2009 08 58:30       31-DEC-2008 12 00:00
12 rows selected.
Elapsed: 00:00:00.12
[pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Previous month end data for report

    Hi expert,
    I have to calculate previous month end data for my report.
    let say if user select 15 oct then he should be able to see 30 sept data.
    I have calander prompt.
    Thanks,

    Hi,
    Use presentation variable in date prompt.
    Apply sql filter(covert to sql) on report as date_column= TIMESTAMPADD(SQL_TSI_DAY,-DAYOFMONTH(date 'presntation_variable'),date 'presentation_variable')
    Refer : How to get LAST_DAY in obiee
    Regards,
    Srikanth

  • Getting Last Month End date

    Dear Experts,
    I want the following result. I have a date parameter. I want to
    get the last / end date of the previous month
    for any given date which the user inputs.
    For ex:
    If user puts the date 15.06.2008
    then i want to get the previous month end date i.e. 31.05.2008.
    The reason being i am creating a program for updating Opening and Closing Stocks of every month in a ZTABLE. The user will put the date in the parameter and system will bring the closing stock of previous month and then calculate for the current month.
    I hope i am not complicating matters too much....
    Basic funda is to arrive at the end date of the previous month for any date which the user puts.
    Please help me... it is mission critical..
    Thanks & Regards,
    Jitesh M Nair

    hi,
    use this to get last month end date.
    ex:
    data: d2 like sy-datum.
    d2 = sy-datum.
    d2+6(2) = '01'.
    d2 = d2 - 1. "prev mnth last date
    write:/ d2.

  • Fetching previous month's date

    Hii,
    Can anyone  provide me the code for retrieving firstWorkingDay for previous month ??

    Hi,
    Please check code:
    import java.text.*;
    import java.util.*;
    public class DateUtils {
      public enum IntervalType {  Month, Week  }
      private DateUtils() {  }
      public static Calendar[] getDateIntervals(IntervalType type, Calendar reference) {
        if (reference == null) {
          reference = Calendar.getInstance();
        Calendar startDate = (Calendar)reference.clone();
        Calendar endDate = (Calendar)reference.clone();
        if (type == IntervalType.Month) {
          // first date of the month
          startDate.set(Calendar.DATE, 1);
          // previous month
          startDate.add(Calendar.MONTH, -1);
          // first date of the month
          endDate.set(Calendar.DATE, 1);
          // previous month, last date
          endDate.add(Calendar.DATE, -1);
        else {
          // previous week by convention (monday ... sunday)
          // you will have to adjust this a bit if you want
          // sunday to be considered as the first day of the week.
          //   start date : decrement until first sunday then
          //   down to monday 
          int dayOfWeek = startDate.get(Calendar.DAY_OF_WEEK);
          while (dayOfWeek  != Calendar.SUNDAY) {
            startDate.add(Calendar.DATE, -1);
            dayOfWeek = startDate.get(Calendar.DAY_OF_WEEK);
          while (dayOfWeek != Calendar.MONDAY) {
            startDate.add(Calendar.DATE, -1);
            dayOfWeek = startDate.get(Calendar.DAY_OF_WEEK);
          // end date , decrement until the first sunday
          dayOfWeek = endDate.get(Calendar.DAY_OF_WEEK);
          while (dayOfWeek  != Calendar.SUNDAY) {
            endDate.add(Calendar.DATE, -1);
            dayOfWeek = endDate.get(Calendar.DAY_OF_WEEK);
        return new Calendar[] { startDate, endDate };
      public static void main(String[] args) {
        try {
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
          System.out.println("** previous month (relative today)");
          Calendar [] results = DateUtils.getDateIntervals(IntervalType.Month, null);
          System.out.println(sdf.format(results[0].getTime()));
          System.out.println(sdf.format(results[1].getTime()));
          System.out.println("** previous week (relative today)");
          results = DateUtils.getDateIntervals(IntervalType.Week, null);
          System.out.println(sdf.format(results[0].getTime()));
          System.out.println(sdf.format(results[1].getTime()));
          System.out.println("** previous month (relative jan 1, 2007)");
          results = DateUtils.getDateIntervals(IntervalType.Month,
            new GregorianCalendar(2007, 00, 1));
          System.out.println(sdf.format(results[0].getTime()));
          System.out.println(sdf.format(results[1].getTime()));
          System.out.println("** previous week (relative jan 1, 2007)");
          results = DateUtils.getDateIntervals(IntervalType.Week,
            new GregorianCalendar(2007, 00, 1));
          System.out.println(sdf.format(results[0].getTime()));
          System.out.println(sdf.format(results[1].getTime()));
        catch (Exception e) {
          e.printStackTrace();
        output :
        ** previous month (relative today)
        2008-06-01
        2008-06-30
        ** previous week (relative today)
        2008-06-30
        2008-07-06
        ** previous month (relative jan 1, 2007)
        2006-12-01
        2006-12-31
        ** previous week (relative jan 1, 2007)
        2006-12-25
        2006-12-31
    this will solve all your requirements!
    Thanks
    Pravesh

  • Delivery Block at PGI level based on GI date and Month end date

    Business need a check on delivery processing based on the Planned GI date, Month end date and transit period. This transit period is a custom field and dependent on customer. Also it is not maintained anywhere in system. Business store it in some excel format.
    The logic needed is: For any given month, the delivery order MUST be goods issued in the same month, i.e. once the order is delivered, the Post goods issue should ONLY be allowed if and only if , the PLANNED GI date ( as maintained in delivery ) + transit time ( at customer level ), falls within the month end date. If not, a block should be applied at PGI and only authorized personnel should be able to release that block.
    Also, there will be no check at invoicing VF01 level. Once the PGI blocked is removed, there will be no check on invoicing. The month end date may vary month to month and need to in combination of Sales Org / Plant as mentioned
    In addition, the business need an exception report where the information of releasing the block should appear for release date, user id of the responsible person, time sales order no etc. and it should be downloadable.
    We can have a custom table to maintain the month end day in given combination.
    But I need your expert inputs as-
    1-     Can we add this transit period in at customer master data as it is dependent on customer and there are huge no of customers for the sales unit? If not, then how to maintain it; may be a z table?
    2-     Based on this logic, what should the code/logic to be written for block at PGI.
    3-     How to control the authority check for removing the block.
    4-     The source fields for exception report.
    Pls revert accordingly.
    Many thanks in advance.

    Hello,
    Please refere the answers to your questions:
    1- Can we add this transit period in at customer master data as it is dependent on customer and there are huge no of customers for the sales unit? If not, then how to maintain it; may be a z table?
    You can either use some un-used Feild in Customer Master or maintain a Z-Table. I believe maintaining a Z-Table would be easy as you have huge number of Customers. You can also write a dmall program to Pick the Customer-wise transit dates from a excel file & store in Z-Table.
    2- Based on this logic, what should the code/logic to be written for block at PGI.
    You have explained the requirement well in your thread, you need to explain the same to your ABAPer & Basis person & they would do the needful.
    3- How to control the authority check for removing the block.
    Basis person would create & assign a Z-Authorization object which the ABAPer would use in his program.
    4- The source fields for exception report.
    Once you do the above development, your ABAPer will easily pick the required feild in Report as he has already used all the feilds somewhere in his development.
    Hope this helps,
    Thanks,
    Jignesh Mehta

  • Month end date

    how to display month end date for every month by default?

    hi,
    chk this code.
    by default it will show the begin and end date in select option.
    the similar think u can adopt.
    check this sample code...
    tables: mkpf.
    data date like sy-datum.
    data date1 like sy-datum.
    select-options: s_date for mkpf-budat.
    initialization.
    CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
    EXPORTING
    iv_date = sy-datum
    IMPORTING
    EV_MONTH_BEGIN_DATE = date
    EV_MONTH_END_DATE = date1
    s_date-option = 'EQ'.
    s_date-sign = 'I'.
    s_date-low = date.
    s_date-high = date1.
    append s_date.
    rgds
    anver
    if hlped mark points

  • 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

  • Previous month last date in sql

    hi
    i am using function
    select dateadd(day,1 - DATEPART(day,dateadd(month,24-36,GETDATE())),dateadd(month, 24- 36, getdate()))
    this will giveme 2014-03-01,
    now what changes  i need to make this function which will give me previous month last date.
    2014-02-28

    Hi coool_sweet,
    The answers in above posts are excellent. In case you may need any tip for date calculation, here is a good link for your reference.
    Date and Time Data Types and Functions - SQL Server (2000, 2005, 2008, 2008 R2, 2012)
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • What is month end data from mbew?

    I have a report that shows valuated stock qty and value that needs to be filtered based on Month End data. (MARD, MBEW).
    How to code this filter "Month End data"?

    MBEWH and MARV are validation points for this. look at MB5W or report J_B1BL07

  • Last month end date based on current date

    Hi,
    How to show last month end date based on the current date.
    Eg:
    Current date = "08/26/09"
    Var- Last Month End Date = "07/31/09" etc...,
    Please help me how to get it...
    Thank You!

    Good to hear that it worked for you. but not for me.
    I tried like this:
    1st::
    1. var1= ToDate("06/30/09","MM/dd/yyyy")
    2.Var2= RelativeDate([Var1];-DayNumberOfMonth([Var1]))
    result: 5/30/09
    2nd:
    RelativeDate('6/30/2009';-DayNumberOfMonth('6/30/2009'))
    result: 5/30/09
    Am working on SAP OLAP cubes.
    Please help me where am going wrong....
    Thank You!

  • Month end date in RPD

    We need to show month end date for a given date in a table.
    Say the date is '03-25-2008', then output should give me '03-31-2008'.
    I want to create a new derived column like this in rpd.
    I believe variables cannot help me here, because we will need to have month end date for each value the date column will hold.
    Please let me know how can we achieve this.

    Hi....
    Better go for creating view by writing the direct function.
    if db is: ORACLE, then LAST_DAY(<date column>) is the function to get the last day of the date column.
    but in creating view you also fetch the key column of the particular date column table and the above function too... it's like
    select key column, LAST_DAY(<date column>) as LastDate from TableNameA
    now you create a physical join between the TableNameA and the view, which maintains 1to1 relation ship.
    So that we can use the LastDate column in our BMP layer in particular TableNameA logical table.
    I think it works out probably....
    If not sorry...
    Thanks & Regards...

  • FOX to read previous month's data

    Hi Guys, i have the following FOX to calculate LINE '57' but cannot read previous month's data.
    please assist.
    DATA LINE TYPE ZBPLINE.
    DATA FISCPER TYPE 0FISCPER3.
    DATA PREV_MONTH TYPE 0FISCPER3.
    DO.
    PREV_MONTH = TMVL (FISCPER , -1) .
    {0BALANCE,FISCPER ,57} = {0BALANCE,PREV_MONTH,57} + {0BALANCE,FISCPER,12}.
    FISCPER  = TMVL(FISCPER , 1).
    IF FISCPER  > PREV_MONTH.
    EXIT.
    ENDIF.
    ENDDO.

    Lerato,
    I am not sure how is your data model, but here are a couple tips
    DATA LINE TYPE ZBPLINE.
    DATA FISCPER TYPE 0FISCPER3. ->>>>>  This sHould probably be 0FISCPER
    DATA PREV_MONTH TYPE 0FISCPER3. ->>>>>  This should probably be 0FISCPER
    data finalmonth type 0FISCPER3. ** or 0fiscper!
    finalmonth = TMVL(FISCPER , 12).
    *initialize you fiscper
    fiscper = '201001'. * or call a variable
    DO.
    PREV_MONTH = TMVL (FISCPER , -1) .
    {0BALANCE,FISCPER ,57} = {0BALANCE,PREV_MONTH,57} + {0BALANCE,FISCPER,12}.
    I am not sure what is 57 and 12. Is it your planning item?
    FISCPER = TMVL(FISCPER , 1).
    This exit if statement should be like this
    if FISCPER  > finalmonth.
    EXIT.
    ENDIF.
    ENDDO.
    Hope that helps
    Alex Zetune
    goldstrategy.com

  • 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')

  • Month end dates caluclation

    Hi guys,
    can any give me an idea..
    i have between calendar prompt...
    when i select from date and to date..
    i need the month end dates of that selected period..
    for example
    from date: 05-may-12 and to date: -19-oct-12
    i need to display May 31st,june 30th,july 31st, august 31st,september 3oth
    can any guide me pls
    Edited by: Bhargav K on Jun 4, 2013 11:19 AM

    Assuming you are using two column prompts 'FromDate' and 'ToDate', try using the following expression as the column formula in your report.
    TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( <FromDate_column>) * -(1) + 1,<FromDate_column>)))
    For the report create two filters, one on FromDate_column and the other on ToDate_column both filtered as is prompted
    Now when you use this report in a dashboard with the dashboard prompt containing the From and To data column prompts, the report will list all the month end dates between the selected range.
    Hope this helps

  • Month End dates

    Hi all,
    I have a table "xyz" which capturing start_date and end_date in a single row.
    i.e. start_date = *15-oct-2007*, end_date = *25-dec-2008*
    I want to write a query which diplay me month end dates of each month which fall between start_date and end_date like . .
    31-oct-2007
    30-nov-2007
    31-dec-2007
    31-jan-2008
    29-feb-2008
    31-mar-2008
    31-dec-2008
    thanks in advance

    Sreekanth Munagala wrote:
    hi,
    try this
    select last_day(add_months(date1,rownum-1))
    from xx_dates
    where empno=1
    connect by (rownum-1) <= round(months_between(date2,date1))
    ROUND won't work because it can round down as well as up.
    SQL> ed
    Wrote file afiedt.buf
      1  with dt as (select to_date('30/10/2007','dd/mm/yyyy') as start_date, to_date('1/12/2008','dd/mm/yyyy') as end_date from dual)
      2  --
      3  select last_day(add_months(start_date,rownum-1)) as end_month
      4  from dt
      5* connect by rownum <= round(months_between(end_date,start_date))+1
    SQL> /
    END_MONTH
    31-OCT-07
    30-NOV-07
    31-DEC-07
    31-JAN-08
    29-FEB-08
    31-MAR-08
    30-APR-08
    31-MAY-08
    30-JUN-08
    31-JUL-08
    31-AUG-08
    30-SEP-08
    31-OCT-08
    30-NOV-08
    14 rows selected.Instead, to do that sort of method you would need CEIL...
    SQL> ed
    Wrote file afiedt.buf
      1  with dt as (select to_date('30/10/2007','dd/mm/yyyy') as start_date, to_date('1/12/2008','dd/mm/yyyy') as end_date from dual)
      2  --
      3  select last_day(add_months(start_date,rownum-1)) as end_month
      4  from dt
      5* connect by rownum <= ceil(months_between(end_date,start_date))+1
    SQL> /
    END_MONTH
    31-OCT-07
    30-NOV-07
    31-DEC-07
    31-JAN-08
    29-FEB-08
    31-MAR-08
    30-APR-08
    31-MAY-08
    30-JUN-08
    31-JUL-08
    31-AUG-08
    30-SEP-08
    31-OCT-08
    30-NOV-08
    31-DEC-08
    15 rows selected.
    SQL>

Maybe you are looking for