Application Development and Automation 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: 

Date conversion from sy-datum format to mm/dd/yyyy

former_member800409
Discoverer
10,389

I'm trying to convert the date 20211229 to MM/DD/YYYY format. But it is getting automatically converted to DD.MM.YYYY.
Code: WRITE id_date to tmp_date MM/DD/YYYY.

Input: 20211229
Output : 29.12.2021

Is there any way to make the date format to be MM/DD/YYYY ?

10 REPLIES 10

jerryjanda
Community Manager
Community Manager
0 Kudos
9,016

Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers, as it provides tips for preparing questions that draw responses from our members. Feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html as well, as that will help you when submitting questions to the community.

I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

Kind regards,

--Jerry

Moderation Lead

Make sure to subscribe to What's New!

Jeansy
Active Contributor
9,016

One possible solution:

DATA: id_date TYPE d VALUE '20211229'.
DATA: tmp_date TYPE char15.

SET COUNTRY 'US'.
WRITE id_date TO tmp_date MM/DD/YYYY.

WRITE: / tmp_date.

DominikTylczyn
SAP Champion
SAP Champion
9,016

Hello levicath

Another possible solution

DATA: id_date TYPE d VALUE '20211229'.
DATA: country type land1 value 'US'.
WRITE: / |{ id_date country = country }|.

Best regards

Dominik Tylczynski

Sandra_Rossi
Active Contributor
9,016

NB: it's explained in the ABAP documentation that MM/DD/YYYY and DD/MM/YYYY behave the same, it depends on current language environment (country).

emanuel_klenner
Active Participant
0 Kudos
9,016

This also depends on your date format settings in the user master. Use transaction SU3 Go to the 'Default's tab and pick the correct date format for the display.

alexis_scotts
Explorer
0 Kudos
9,016

If you want to display it then use following statement.

write 'Date:' sy-datum | dd.mm.yyyy.

0 Kudos
9,016

Your code doesn't compile.

RaymondGiuseppi
Active Contributor
0 Kudos
9,016

Another solution

REPORT z_demo_date.

DATA: o_date   TYPE c LENGTH 10,
      o_format TYPE xudatfm. " F4 for free (2 is MM/DD/YYYY)

PARAMETERS: i_date   TYPE d,
            i_format TYPE xudatfm.

START-OF-SELECTION.

  TRY.
      cl_abap_datfm=>conv_date_int_to_ext(
        EXPORTING
          im_datint    = i_date
          im_datfmdes  = i_format
        IMPORTING
          ex_datext    = o_date
          ex_datfmused = o_format
          ).
      MESSAGE o_date TYPE 'S'.
    CATCH cx_abap_datfm_format_unknown .
      MESSAGE 'bad boy' TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

0 Kudos
9,016

User profile set date format to MM/DD/YYYY, you can get right output with code WRITE id_date to tmp_date.

Shruthi29
Explorer
0 Kudos
9,016

Hi,

try this solution

DATA: DATE TYPE SY-DATUM.

DATE = SY-DATUM.

DATA: date1(10).

SET COUNTRY 'IN'.

WRITE: DATE TO date1.

WRITE: / date1.

SET COUNTRY 'US'.