Skip to Content
avatar image
Former Member

Convert Internal Date YYYYMMDD to string in external format

Hi,

This question has probably been asked thousands of times before but I did a quick search and couldn't find an answer to my specific question.

I'm writing the internal date to a string field (to be used in batch input of program RFBIBL00). I want to take user parameters into consideration, so if they have their default set to US date MMDDYYYY it will post like that or UK format DDMMYYYY.

At the moment I'm moving the date like this:

  wa_string-line+35(2) = s_podate+6(2).
  wa_string-line+37(2) = s_podate+4(2).
  wa_string-line+39(4) = s_podate(4).

which works for DDMMYYYY users but no one else.

Is there a function module that will convert the internal date to the correct user format but without / or . in the middle?

I need the date in MMDDYYYY not MM/DD/YYYY or MM.DD.YYYY.

Thanks,

Gill

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • avatar image
    Former Member
    Nov 13, 2008 at 12:09 PM

    you can use FM /SAPDII/SPP05_CONVERT_DATE for conversion.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 13, 2008 at 12:14 PM

    Hi,

    try this FM

    FORMAT_DATE_4_OUTPUT

    EX:

    Import :  20.10.2008
              MMDDYYYY
    
    Output:  10202008.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 13, 2008 at 12:16 PM

    Hi,

    Try this FM : "CONVERT_DATE_TO_INTERN_FORMAT"...

    Regards,

    Ravi Kiran.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 13, 2008 at 12:17 PM

    Hello Gill,

    To convert the date format to the internal date format i.e. the date format set for the user you can use FM 'CONVERT_DATE_TO_INTERN_FORMAT'.

    Hope it help.

    Thanks,

    Jayant

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 13, 2008 at 12:17 PM

    Thanks but I solved it myself using the following code:

      CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
        EXPORTING
          date_internal            = s_podate
        IMPORTING
          date_external            = ex_podate
        EXCEPTIONS
          date_internal_is_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.
      REPLACE ALL OCCURENCES OF '/' IN ex_podate WITH space.
    

    This gives me MMDDYYYY or DDMMYYYY based on the user defaults.

    Add comment
    10|10000 characters needed characters exceeded

    • hi Gill,

      I hope you are still following your own thread (even if it is marked as answered), the simpliest solution is:

      WRITE gv_date TO string.

      (gv_date is a date in internal format)

      this simple statement will always write the date acc. to the current user settings.

      hope this helps

      ec