‎2010 Mar 10 5:49 AM
Hi ppl,
I need an FM to change the date format into the format maintained in the default settings for the user.
E.g.
if the default date format maintained is MM-DD-YYYY, then the system date YYYYMMDD should be conveted to MM-DD-YYYY.
if the default date format maintained is MM/DD/YYYY, then the system date YYYYMMDD should be conveted to MM/DD/YYYY.
and so on for other formats...
Please let me know if there is any standard FM or any logic to achieve this.
Regards.
‎2010 Mar 10 6:07 AM
I'd go for the very nice simple WRITE statement:
data date_string type char10.
write sy-datum to date_string.
write / date_string.
This will automatically apply the user settings. No need for overhead of function/method calls...
‎2010 Mar 10 5:56 AM
Hi,
Step 1.
SELECT SINGLE datfm
INTO fp_datefm
FROM usr01
WHERE bname = sy-uname.
Step 2.
TRY.
CALL METHOD cl_abap_datfm=>conv_date_int_to_ext
EXPORTING
im_datint = l_intdate
im_datfmdes = fp_datefm
IMPORTING
ex_datext = l_extdate. "External Format
CATCH cx_abap_datfm_format_unknown.
WRITE:/ text-033.
ENDTRY.
Regards.
Sarbajit.
‎2010 Mar 10 6:02 AM
hi
try the function module CONVERT_DATE_TO_INTERN_FORMAT.
hope this helps
Regards
Ritesh
‎2010 Mar 10 6:06 AM
Hi sarbajit,
The class mentioned by you does not exist in our system.
Hi Ritesh,
The FM works the other way round. It converts MM-DD-YYYY to YYYYMMDD.
Please let me know if there isany other solution possible.
Regards,
‎2010 Mar 10 6:03 AM
Hi,
You can try this way.
1.Execute the FM SLS_MISC_GET_USER_DATE_FORMAT to the format of the USER.
2.Then format the date according to it.
You can use FM HR_IN_GET_DATE_COMPONENTS to get the components
else you can use the below logic.
IDATE will have the date in internal format i.e. "YYYYMMDD".
DAY = IDATE+6(2).
MONTH = IDATE+4(2).
YEAR = IDATE+0(4).
Thanks & Regards,
Vamsi.
‎2010 Mar 10 6:07 AM
I'd go for the very nice simple WRITE statement:
data date_string type char10.
write sy-datum to date_string.
write / date_string.
This will automatically apply the user settings. No need for overhead of function/method calls...
‎2010 Mar 10 6:14 AM
Hi Harald,
Thanks a million.
This is an awesome solution. I am surprised I was not aware about this yet.
I hope it will work under all scenarios and even after system upgrades. Please let me know if there are any exceptions.
Thanks.
‎2010 Mar 10 6:34 AM
I've been using this since release 3.1 (didn't work on SAP before that) and it always worked fine. I'd say that this approach is bound to be pretty safe for upcoming release upgrades...