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....

Similar Messages

  • 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

  • Need to find the last day of the previous month

    hi folks,
    the code goes like this...
    data: xt247 type t247,
          monthn(30) type c,
          monthnumber type i,
          bforwardmonth type i.
    call function 'RP_LAST_DAY_OF_MONTHS'
      EXPORTING
        day_in            = s_date
      IMPORTING
        last_day_of_month = e_date.
    write: 'The last day of the month', e_date.
    select single * from t247 into xt247
            where spras = sy-langu
              and mnr = e_date+4(2).
    monthnumber = xt247-mnr.
    write:' The month number', monthnumber.
    determine the previous month.
    bforwardmonth = monthnumber - 1.
    From here I need to determine the last day of the previous month How can I do?
    Thanks for your help.
    Santhosh

    Hi all,
    here's the shortest solution:
    REPORT z123.
    PARAMETERS p_datum LIKE sy-datum DEFAULT sy-datum.
    DATA ultimo  LIKE sy-datum.
    <b>ultimo = p_datum - p_datum+6(2).</b>
    WRITE: / p_datum, 20 ultimo COLOR 2.
    it's not my solution :
    it's from <a href="http://www.abapforum.com/forum/viewtopic.php?t=1434&highlight=ultimo">Andrew_</a>
    regards Andreas

  • How to get last day of prev month?

    SELECT to_char(SYSDATE, 'MM') -1, last_day(sysdate)
    FROM DUAL;
    If current month is April, How to get the last day of March? Thanks.

    SQL> select sysdate, trunc(sysdate, 'mm') - 1 from dual ;
    SYSDATE     TRUNC(SYSDA
    06-APR-2004 31-MAR-2004
    1 row selected.
    SQL>

  • How to get last day of the year

    Hi All ,
    Thanks in advance ...
    How will I get the last day of the year as I am passing date at run time .
    I can manage to get first day of year by
    SELECT TRUNC(SYSDATE,'YEAR') AS FDAY_YEAR
    from dual
    Thanks in advance
    Regards
    Sachin

      1*  select ADD_MONTHS(trunc(sysdate,'yyyy'),12)-1 dd from dual
    SQL> /
    DD
    31-DEC-2010

  • How to get last day of a month

    using pl/sql
    What i need is that all members whose birthdate is in the curren month will be included as having had their birthdate regardless of the date of the month. The code i have is:
    Select me607.subscriber_id
    me607.mbr_dob,
    ** trunc(months_between (*end of current month*,me607.mbr_dob) / 12) as age
    from odw.mbr607_member_expanded me607
    The asterixed line is what I need to change. If I put the end of the current month (where I put 'end of current month') then all those whose birthday month is in Feb will show as having had their birthdate. So if run today, folks whose birthdate is 26-feb-2005 will show an age of 5.
    When grabbing the last day of the month using visual basic I just use the first day of the subsequent month minus 1. Any assistance is appreciated..

    Hi,
    This does what you requested:
    Select  me607.subscriber_id,     -- Don't you need a comma here?
         me607.mbr_dob,
         ROUND ( MONTHS_BETWEEN ( SYSDATE
                                , me607.mbr_dob
               / 12
    from    odw.mbr607_member_expanded     me607
    WHERE     TO_CHAR (me607.mbr_dob, 'MONTH') =
         TO_CHAR (SYSDATE,      'MONTH')
    ;If this is run sometime in February, 2010, and mbr_dob is sometime in Febrary, 2005, then the result of MONTHS_BETWEEN will be between 59 and 61. When we divide by 12 convert that to years, that difference of up to one month becomes so small that it will be lost in the rounding.
    If this isn't exactly what you need, tthen post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    Edited by: Frank Kulash on Feb 17, 2010 1:32 PM
    Added explanation.

  • Getting last date of the previous  month

    Hi
       Am giving one date. FOr that day i hav to take previous month last date.
    How can i do. IMportant : Last date of previous month

    u can make the code work like this.
    data: date like sy-datum,
          date1 like sy-datum.
    date = sy-datum.
    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
      EXPORTING
        day_in                  = date
    IMPORTING
       LAST_DAY_OF_MONTH       = date1
    EXCEPTIONS
       DAY_IN_NO_DATE          = 1
       OTHERS                  = 2
    add 1 to date1.
    write:/ 'next month start date:', date1.
    *to fetch the march month last date.
    date1+4(2) = 03.
    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
      EXPORTING
        day_in                  = date1
    IMPORTING
       LAST_DAY_OF_MONTH       = date1
    EXCEPTIONS
       DAY_IN_NO_DATE          = 1
       OTHERS                  = 2
    write:/ 'last date of march:', date1.
    Please close your previous threads.

  • Getting data in a query on last date of all previous months

    Dear Experts,
    I need your help with a query.
    I am trying to create a query which when run should pick the number of Open Sales Order on the last date of all the previous months from the start of company.
    I could create the query for fetching the required data on last day of the previous month, say today is 25th June 2014, so my query only fetches data for May 31st 2014 but I need data for all previous month, May 31st 2014, April 30th 2014, March 31st 2014 & so on.
    Please advise how to achieve this is SQL query.
    Thanks & regards,
    Nitin

    Hi,
    Try this:
    Select *
    from(
    SELECT T0.[DocNum] as #,t0.cardcode as C, t0.docdate
    FROM ORDR T0
    WHERE T0.[DocStatus] = 'o' and T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-1,0)),10) OR T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-2,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-3,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-4,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-5,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-6,0)),10) or T0.[DocDate]  = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-7,0)),10)
    group by t0.cardcode,docdate,T0.[DocNum]) S
    pivot
    (count(#) for c in([cvt01],[cvt02],[cvt03],[cvt04],[cvt05],[cvt06],[cvt07],[cvt08],[cvt12])) P
    Note: Replace Cvt01,02...with your customer code.
    Thanks & Regards,
    Nagarajan

  • How to get the last day of the next month?

    Hi all.
    I need to get the last day of the next month. E.g. if the date is 20.03.2008 I need to get 30.04.2008.
    Is there any FM for it?
    TIA, Nikolai.

    hi Nikolai,
    pls. have a look athe following piece of code:
    PARAMETERS : p_date TYPE sy-datum.
    DATA : gv_res TYPE sy-datum.
    CALL FUNCTION 'CALCULATE_DATE'
    EXPORTING
    *   DAYS              = '0'
       months            = '2'
       start_date        = p_date
    IMPORTING
       result_date       = gv_res.
    ==> Now you have (gv_res) 2 months later as today
    gv_res+6(2) = '01'. ==> gv_res is first day of next-next month
    gv_res = gv_res - 1. ==> gv_res is last day of next month
    hope this helps
    ec

  • Dynamic variable to get last day of month

    Hi all,
    I have created one report where in YTD is calculated based on stsyem date. NOw in this report the cal month is in row thus displaying data month wise. But i need one key figure which giving the last day vaue of every month that are displayed in YTD i.e this is based on cal day. Thus the report layout is as follows:
    if report is run in mar 2007 then it should display:
    For calmonth       key figure due amount
    For Jan 07           this should show due value on last day of jan 07 (i.e 31st jan 07)
    for Feb 07           this should show due value on last day of feb 07 (i.e 28th feb 07)
    for Mar 07          this should show due value on last day of mar 07 (i.e 31st mar 07)
    customer exit variable can give me only one value at a time. How can I make it dynamic to take last day value of every month as per cal month. Could anybody explain me if worked on any such issue.
    If there is some how to paper kindly mail me at my email Id : [email protected]
    thanks in advance
    Regards,
    Wrushali

    Hi,
    U can use FM : SLS_MISC_GET_LAST_DAY_OF_MONTH to get the last day of the month by passing the date/current date.
    Thanks,
    Debasish

  • How to get last date of the week

    hi,
    how to get last date of the week like FM WEEK_GET_FIRST_DAY gives the date of the first day of the week i need the date of the last day of the week..
    thnx

    data : p_week type KWEEK,
    p_Date type SYDATUM.
    p_week = <incoming value in week of year>
    CALL FUNCTION 'WEEK_GET_FIRST_DAY'
    EXPORTING
    week = p_week
    IMPORTING
    DATE = p_date
    EXCEPTIONS
    WEEK_INVALID = 1
    OTHERS = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    To get the last day of the week.
    p_date = p_date + 6.
    You can find the available fm in the system from se37 transaction code.

  • Getting last day of the month

    hi ,
    is there an existing date funtion to get last day of the month ?
    pls advise
    else
    i'll try to add_month + 1 to current month and format to the first day and minus 1 day from that new month
    tks & rdgs

    last_day function
    <br>
    jeneesh

  • How to get last Build date of a dll in the real time target

    Info On My Project    
       I am working on LabWindows CVI 12.0 for development . This project is a real time application for hardware, which is having Phar Lap ETS as RTOS...  
    I am facing some problems while checking Build date of my Application file( .dll)
    I have tried to use GetFileDate API. But it is not supporting for realtime Target..
    So i have tried __DATE__ macro.. That also having some problems..
    How to get last Build date of a dll from the real time target  ??
    Please Help to solve this....
    Thanks
    Vaishakh A  K

    Please reply if any one have suggestion...

  • How to Get last page number in report 10g

    I want to get last page number in report but Current page number found from srw.get_page_num(n)
    but i want to get last page number for conditional formating like this
    srw.get_page_num(current_page)=last_page
    pls help me how can get last page number;
    pls help;
    thanks in advanced;

    Hi,
    you can use the Property Print Object On for this.
    Regards
    Rainer

  • Customer Exit to get last day of month from Year/month

    Hi Experts,
    I need to create a customer exit to get the last day of month from Cal Year month input variable.
    Examples
    1)
    User input period: 12.2008
    I need from the customer exit: 31.12.2008
    2)
    User input period: 02.2009
    I need from the customer exit: 28.02.2009
    Can someone help me with the ABAP code to achieve this with a customer exit?
    Help will be appreciated.

    Hi,
    Please use the following code,
    Second one is the suitable solution for you, I can understand that, if it leafe year then you have the problem so use the secon one.
    First one is using Period i.e. 010.2008 (December 2008).
    Secodn one is based on Date/Month.
    Note: Insted of SY-DATUm, you give your variable name
    *******To get the Last day of the Fy Period entered by User in ZFYP***
        WHEN 'ZLDAY_FI'.
          LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZFYP'.
            zbdatj = loc_var_range-low+0(4).
            zbuper = loc_var_range-low+4(3).
            CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
              EXPORTING
                i_gjahr = zbdatj
                i_periv = 'V3'
                i_poper = zbuper
              IMPORTING
                e_date  = zzdate.
            CLEAR: l_s_range.
            l_s_range-low = zzdate.
            l_s_range-sign = 'I'.
            l_s_range-opt = 'EQ'.
            APPEND l_s_range TO e_t_range.
          ENDLOOP.
    Note: in the below code I given SY-DATUM, so you change to your Month Variable like using  
    LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'XXXX'.
    ** Last Day of Current Calendar month
          zzdate = sy-datum.
          CALL FUNCTION '/OSP/GET_DAYS_IN_MONTH'
            EXPORTING
              iv_date = zzdate
            IMPORTING
              ev_days = znum.
          CLEAR: l_s_range.
          l_s_range-low+6(2) = znum.
          l_s_range-low+0(4) = sy-datum+0(4).
          l_s_range-low+4(2) = sy-datum+4(2).
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO e_t_range.
    Thanks
    Reddy
    Edited by: Surendra Reddy on Jan 27, 2009 2:47 PM
    Edited by: Surendra Reddy on Jan 28, 2009 6:12 AM

Maybe you are looking for

  • Importing from iMovie 09

    I have iMovie 09 and I just bought Final Cut Express. I created a simple movie in iMovie 09. I exported it as Final Cut XML. I imported the file in Final Cut Express. All as described in the Final Cut Express video tutorial. However, I just get a "Me

  • GTS and FI intergration

    Hi, Currently we are implementing SAP GTS 7.2, we need to do SPL check on payment run. When the payment proposal is generated in ECC - get an error as u201CTechnical error when checking in GTSu201D the message class is u201CFIPAY_GTSu201D but in GTS

  • How to check service failover  in RAC system

    Hi experts, We have 4 nodes with oracle 10G2 at redhat. we create some service with failover function. some service is not. total 4 services is in system. I try to use below SQL to find services failover function. == select INST_ID,STATUS, FAILOVER_T

  • Av check query

    SETTING: Availability check is activated both at schedule line level(VOV6)  as well as the delivery item category level (OVLP). So according to the settings the availability check will be carried out in sales and delivery as well. I can see that avai

  • Class to run standard SAP Query

    Hi, Could you help me with finding standard SAP class to run query created in SQ01? Thank you