Skip to Content
avatar image
Former Member

to change the date format

hi experts

my problem is to change the date format.actualy the input is 14.10.2008 but i have to change this format like 20081014.so ple give me some code.the output is 20081014. ple adjunt

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • avatar image
    Former Member
    Oct 17, 2008 at 03:57 AM

    USE FUNCTION MODULE :

    FORMAT_DATE_4_OUTPUT
    DATIN =14.10.2008
    FORMAT = YYYY/MM/DD

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 17, 2008 at 03:58 AM

    Hi,

    data : date type sy-datum,

    var1 type char 15.

    initialization.

    date = sy-datum.

    end of selection.

    concatenate date0(4) date4(2) date+6(2) into var1.

    write var1.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 17, 2008 at 04:03 AM

    Hi,

    SAP internal format will be 20081014 type what ever you give in different format, you can check that in Debugging mode and give SY-DATUM, it will display the format in which you want.

    Do you want that to display in OUTPUT, do that using Concatenate statement. declaring 3 fields, and use officet to read the values.

    Regards

    Bala Krishna

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 17, 2008 at 04:05 AM

    Hi,

    Use the FM CONVERT_DATE_TO_INTERNAL;

    Data : date_in(10) type c,
           date_out type d.
    
    date_in = '14.10.2008'.
    BREAK-POINT.
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
      EXPORTING
        date_external                  = date_in
     IMPORTING
       DATE_INTERNAL                  = date_out
     EXCEPTIONS
       DATE_EXTERNAL_IS_INVALID       = 1
       OTHERS                         = 2.

    date_out will have date in format 20081014.

    Regards

    Karthik D

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 17, 2008 at 04:40 AM

    Hi Sree,

    What Karthik wrote was correct. May be you directly used WRITE stmt for the output.

    Karthik i am modifing your code a bit.

    Sree try this out

    Data : date_in(10) type c,
           date_out type d.
    
    DATA : DATE_FORMATTED TYPE CHAR10.
    
    date_in = '14.10.2008'.
    
    CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
      EXPORTING
        date_external            = date_in
      IMPORTING
        DATE_INTERNAL            = date_out
      EXCEPTIONS
        DATE_EXTERNAL_IS_INVALID = 1
        OTHERS                   = 2.
    
    DATE_FORMATTED = date_out.
    
    WRITE date_formatted.

    Regards

    Edited by: Rajvansh Ravi on Oct 17, 2008 6:41 AM

    Add comment
    10|10000 characters needed characters exceeded