Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

abap

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?

like image 899
ilya n. Avatar asked Oct 13 '09 08:10

ilya n.


4 Answers

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

like image 75
mydoghasworms Avatar answered Oct 23 '22 00:10

mydoghasworms


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

like image 39
PATRY Guillaume Avatar answered Oct 23 '22 01:10

PATRY Guillaume


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.
like image 3
Muhammad Ramzan Avatar answered Oct 23 '22 02:10

Muhammad Ramzan


* 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

like image 2
TheDean Avatar answered Oct 23 '22 02:10

TheDean