2022 Apr 04 5:14 PM
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 ?
2022 Apr 04 5:14 PM
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
2022 Apr 04 6:28 PM
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.
2022 Apr 04 7:32 PM
2022 Apr 04 8:29 PM
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).
2022 Apr 07 1:22 AM
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.
2022 Apr 13 9:03 AM
If you want to display it then use following statement.
write 'Date:' sy-datum | dd.mm.yyyy.
2022 Apr 13 10:11 AM
2022 Apr 13 4:31 PM
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.
2022 Apr 15 8:12 AM
User profile set date format to MM/DD/YYYY, you can get right output with code WRITE id_date to tmp_date.
2022 Apr 15 1:33 PM
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'.