Skip to Content
author's profile photo
Former Member

Get last day in a month

I want to get the last date in a month. I let the user choose a date, for example 20050509 and want the "result" to be 20050531.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • author's profile photo
    Former Member
    Sep 28, 2005 at 11:29 AM

    Hi

    there are several fm find out the last day of month:

    LAST_DAY_OF_MONTHS

    RE_LAST_DAY_OF_MONTH for example

    Max

    Message was edited by: max bianchi

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Sep 28, 2005 at 11:32 AM

    Hi,

    data: date type d.

    date = sy-datum.

    date+6(2) = '01'.

    date = date + 31.

    date+6(2) = '01'.

    date = date - 1.

    Svetlin

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Sep 28, 2005 at 11:33 AM

    Hi,

    You can also use NUMBER_OF_DAYS_PER_MONTH_GET to get the number of days in any month.

    The last day will of course be the last date for the month. This FM also works for leap yrs.

    Sudha

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Sep 28, 2005 at 11:41 AM

    Hi,

    Further to this if you want to find the name of the day

    that LAST_DAY_OF_MONTHS gives out use the FM

    <b>RH_GET_DATE_DAYNAME</b>.

    Ex:

    For today's date <b>09/28/2005</b> it gives out

    <b>Wednesday</b>.

    Please reward points if you find this explanation useful.

    Regards,

    Siva

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 28, 2005 at 11:47 AM

    Also u can do as

    DATA: ws_c_date(8)  TYPE c,
    
    s_date = '20050509'
    p_list = s_date+6(2).
    p_list1 = s_date+0(4).
    
      CALL FUNCTION <b>'NUMBER_OF_DAYS_PER_MONTH_GET'</b>
             EXPORTING
                  par_month = p_list
                  par_year  = p_list1
             IMPORTING
                  par_days  = ws_n_days.
    
    <i>*  For Concatenating the month and year into the date format</i>
    
    CONCATENATE  p_list1  p_list ws_n_days INTO ws_c_date.

    Hope this too helps u.

    Kindly reward points for the helpful answer and close the thread.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Here's example how you can use FM RE_LAST_DAY_OF_MONTH:

      data: w_last_day(2) type c.
      
      CALL FUNCTION 'RE_LAST_DAY_OF_MONTH'
        EXPORTING
          I_DATUM        = sy-datum
       IMPORTING
      *   E_KZ_ULT       =
         E_TT            = w_last_day
                .
      write: w_last_day.

      Regards,

      Ville

  • author's profile photo
    Former Member
    Sep 28, 2005 at 12:24 PM

    I have now solved it. Thanks everybody!

    Add comment
    10|10000 characters needed characters exceeded