How to format date as a DD, Month, Year?

22,565

Solution 1

You can get the month's name in a given language using the module function 'MONTH_NAMES_GET', passing the language as a parameter. The day (Sunday for example) can also be obtained using 'RH_GET_DATE_DAYNAME'

Guillaume

Solution 2

I think the absolute simplest way would be to apply the conversion exit LDATE to your date field. Easiest is to call function module CONVERSION_EXIT_LDATE_OUTPUT.

This would for example convert

20090101

to

01. January 2009

(Unless you need to actually have the day, month text and year in separate strings, which you seem to indicate. Anyway, maybe it will help someone else).

Solution 3

This code will give you the date in the long text format like 'December 02, 2011'. You may change the code accordingly to print the date with long MONTH name.

DATA: LONG_DATE(20).
PERFORM GET_LONG_DATE USING LONG_DATE.
WRITE: LONG_DATE.

FORM GET_LONG_DATE USING DATE.

DATA: T_MONTH_NAMES LIKE TABLE OF T247 WITH HEADER LINE.

CALL FUNCTION 'MONTH_NAMES_GET'
 EXPORTING
   LANGUAGE     = SY-LANGU
  TABLES
    MONTH_NAMES = T_MONTH_NAMES
  .

DATA: YEAR(4)   TYPE C,
      MONTH(2)  TYPE C,
      DAY(2)    TYPE C.

YEAR = SY-DATUM+(4).
MONTH = SY-DATUM+4(2).
DAY = SY-DATUM+6(2).


READ TABLE T_MONTH_NAMES INDEX ( MONTH ).

CONCATENATE T_MONTH_NAMES-LTX ' ' DAY  INTO DATE SEPARATED BY SPACE.
CONCATENATE DATE ',' INTO DATE.
CONCATENATE DATE YEAR INTO DATE SEPARATED BY SPACE.

WRITE / DATE.

ENDFORM.

Solution 4

* to get full name of the day / month also can use


          GET_MONTH_NAME ... for month and 
            GET_DATE_DAYNAME for the specific day name too

and other methods to get other format of the date are

  • Using the WRITE statement

            data: get_date(10).  "field to store output date
    
    • Converts SAP date from 20130901 to 01.09.2013

          write sy-datum to get_date dd/mm/yyyy.
      
    • Converts SAP date from 20130901 to 01.09.13

          write sy-datum to get_date dd/mm/yy.
      
    • Using data manipulation techniques

      data: get_date(8).  "field to store output date
      
    • Converts SAP date from 20130901 to 01092013

           get_date(2)   = sy-datum+6(2).
           get_date+2(2) = sy-datum+4(2).
           get_date+4(4) = sy-datum(4).
      
    • Using Function modules

          data: get_date(8).  "field to store output date
      
    • Converts date from 20130901 to 01SEP2013

          get_date   = sy-datum.
      

      CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'

             EXPORTING
      
        input         = get_date
      
              IMPORTING
      
           OUTPUT        = get_date.
      

      these all the formats you can use for the specific dates/months and year

Solution 5

Normally you can also export the date into the plant level country specific date format:

if w_country is initial.
  select single LAND1
    from T001W
    into w_country
   where WERKS eq w_the_plant.
endif.

SET COUNTRY w_country.

write w_the_date to w_export.
Share:
22,565

Related videos on Youtube

ilya n.
Author by

ilya n.

I'm a math guy with a history of coding as a hobby and a big interest in design. Since web combines design, programming and interaction with people, I'm enjoying developing. It's partly paid, partly just stuff for fun.

Updated on July 17, 2021

Comments

  • ilya n.
    ilya n. almost 3 years

    I need to split ABAP date like

    20091101 --> "01", "november", "2009"
    

    The "01" and "2009" are trivial, but how do I get the month name (which should be localized)?

    Is there a function to do that?

    If there is no such function, perhaps a table with month names?

Related