Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Internal Date YYYYMMDD to string in external format

Former Member
0 Kudos

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

6 REPLIES 6

Former Member
0 Kudos

you can use FM /SAPDII/SPP05_CONVERT_DATE for conversion.

Former Member
0 Kudos

Hi,

try this FM

FORMAT_DATE_4_OUTPUT

EX:

Import :  20.10.2008
          MMDDYYYY

Output:  10202008.

Former Member
0 Kudos

Hi,

Try this FM : "CONVERT_DATE_TO_INTERN_FORMAT"...

Regards,

Ravi Kiran.

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

0 Kudos

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