WTF Solution

Convert Date Format in SAP ABAP from SY-DATUM or DD.MM.YYYY to any in 2025

 I know that you are required to convert the system date format to the user-required date format without using a function module. Read some examples of conversion of the date format in SAP ABAP.

Date is a variable and its data type is character because other data types are can not be compatible to store converted date. SY-DATUM is a system variable that store system date. If system date is 04.03.2022, Then SY-DATUM store 04.03.2022 .

Example - 1:  SY-DATUM  or DD.MM.YYYY  To  DD

DATA: DATE TYPE CHAR10.

WRITE: ' SYSTEM DATE = ',SY-DATUM.
DATE = SY-DATUM+6(2).
WRITE: /,'CONVERTED DATE = ',DATE.

Output-1

        SYSTEM DATE = 04.03.2022
CONVERTED DATE = 04

Explanation:

SY-DATUM+6(2) that means after 6 character show only 2 character in the value of SY-DATUM variable (count start right to left of the system date). But at the counting time system use character format date(20220304) and count start left to right .

Example - 2: SY-DATUM  or  DD.MM.YYYY  To  MM

DATA: DATE TYPE CHAR10.

WRITE: ' SYSTEM DATE = ',SY-DATUM.
DATE = SY-DATUM+4(2).
WRITE: /,'CONVERTED DATE = ',DATE.

Output-2

        SYSTEM DATE = 04.03.2022
CONVERTED DATE = 03

Explanation:

SY-DATUM+4(2) means that after 4 characters you want to display only 2 characters in the value of the SY-DATUM variable (count starts right to left of the system date). But the counting time system uses a character format date(20220304) and counts start left to right .

Example - 3: SY-DATUM  or  DD.MM.YYYY   To  YYYY

DATA: DATE TYPE CHAR10.

WRITE: ' SYSTEM DATE = ',SY-DATUM.
DATE = SY-DATUM+0(4).
WRITE: /,'CONVERTED DATE = ',DATE.

Output-3

        SYSTEM DATE = 04.03.2022
CONVERTED DATE = 2022

Explanation:

SY-DATUM+0(4) that means after 0 character show only 4 character in the value of SY-DATUM variable (count start right to left of the system date). But at the counting time system use character format date(20220304) and count start left to right .

Example - 4: SY-DATUM  or  DD.MM.YYYY  To  DD-MM-YYYY

DATA: DATE TYPE CHAR10.

WRITE: ' SYSTEM DATE = ',SY-DATUM.
CONCATENATE SY-DATUM+6(2) '-' SY-DATUM+4(2) '-' SY-DATUM+0(4) INTO DATE.
WRITE: /,'CONVERTED DATE = ',DATE.

Output-4

        SYSTEM DATE = 04.03.2022
CONVERTED DATE = 04-03-2022

Explanation:

CONCATENATE that means add two or more character or string value. If system date is 04.03.2022, Then SY-DATUM+6(2) is 04 and SY-DATUM+4(2) is 03 and SY-DATUM+0(4) is 2022. First add 04 and '-' and after add 03 and '-' and 2022 and after add, All that can store into the date variable.

Example - 5: SY-DATUM   or  DD.MM.YYYY  To  DD/MM/YYYY

DATA: DATE TYPE CHAR10.

WRITE: ' SYSTEM DATE = ',SY-DATUM.
CONCATENATE SY-DATUM+6(2) '/' SY-DATUM+4(2) '/' SY-DATUM+0(4) INTO DATE.
WRITE: /,'CONVERTED DATE = ',DATE.

Output-5

        SYSTEM DATE = 04.03.2022
CONVERTED DATE = 04/03/2022

Explanation:

Example-4 and Example-5 both are same but only different - symbol and / symbol. Example-4 convert to DD-MM-YYYY AND EXAMPLE-5 CONVERT to DD/MM/YYYY.

Example - 6: SY-DATUM  or  DD.MM.YYYY   To  YYYY/MM/DD

DATA: DATE TYPE CHAR10.

WRITE: ' SYSTEM DATE = ',SY-DATUM.
CONCATENATE SY-DATUM+0(4) '/' SY-DATUM+4(2) '/' SY-DATUM+6(2) INTO DATE.
WRITE: /,'CONVERTED DATE = ',DATE.

Output - 6

        SYSTEM DATE = 04.03.2022
CONVERTED DATE = 2022/03/04

Explanation:

Example-5 and Example-6 both are same but only different reverse of a example-5 date. Example-5 convert to DD/MM/YYYY AND EXAMPLE-6 CONVERT to YYYY/MM/DD.

Example - 7: SY-DATUM  or  DD.MM.YYYY   To  MM/DD/YYYY

DATA: DATE TYPE CHAR10.

WRITE: ' SYSTEM DATE = ',SY-DATUM.
CONCATENATE SY-DATUM+4(2) '/' SY-DATUM+6(2) '/' SY-DATUM+0(4) INTO DATE.
WRITE: /,'CONVERTED DATE = ',DATE.

Output - 7

        SYSTEM DATE = 04.03.2022
CONVERTED DATE = 03/04/2022

Explanation:

Example-5 and Example-7 both are same but only different position of a date and month. Example-5 convert to DD/MM/YYYY AND EXAMPLE-7 CONVERT to MM/DD/YYYY.

Example - 8: SY-DATUM or DD.MM.YYYY To Current year / Next year

DATA: DATE1 TYPE DATS,
DATE TYPE CHAR10.

WRITE: 'SYSTEM DATE = ',SY-DATUM.
DATE1 = SY-DATUM + 365.
CONCATENATE SY-DATUM+0(4) '/' DATE1+0(4) INTO DATE.
WRITE: /,'CONVERTED DATE = ',DATE.

Output - 8

SYSTEM DATE = 04.03.2022
CONVERTED DATE = 2022/2023

Explanation:

In this case DATE1 is a variable and its data type is dats. If system date is 04.03.2022, Then SY-DATUM is 04.03.2022. SY-DATUM + 365 means system date plus one year is 04.03.2023 and that date store DATE1. Then SY-DATUM+0(4) is 2022 and DATE1+0(4) is 2023 and both date are store DATE variable and show.

Example - 9: YYYY MM DD  To  DD.MM.YYYY date format in SAP ABAP

DATA: UDATE TYPE CHAR10,
             CDATE TYPE CHAR10.

DATE = '20220910'.
WRITE: ' USER DATE = ',UDATE.
CONCATENATE UDATE+6(2) '.' UDATE+4(2) '.' UDATE+0(4) INTO CDATE.
WRITE: /,'CONVERTED DATE = ',CDATE.

Output-9

        USER DATE = 20220910
CONVERTED DATE = 10.09.2022

Explanation:

CONCATENATE that means add two or more character or string value. If user date is 20220910, Then UDATE+6(2) is 10 and UDATE+4(2) is 09 and UDATE+0(4) is 2022. First add 10 and '.' and after add 09 and '.' and 2022 and after add, All that can store into the CDATE variable.

Example - 10: YYYY DD MM  To  DD.MM.YYYY date format in SAP ABAP

DATA: UDATE TYPE CHAR10,
             CDATE TYPE CHAR10.

DATE = '20223012'.
WRITE: ' USER DATE = ',UDATE.
CONCATENATE UDATE+4(2) '.' UDATE+6(2) '.' UDATE+0(4) INTO CDATE.
WRITE: /,'CONVERTED DATE = ',CDATE.

Output-10

        USER DATE = 20223012
CONVERTED DATE = 30.12.2022

Explanation:

CONCATENATE that means add two or more character or string value. If user date is 20220910, Then UDATE+4(2) is 10 and UDATE+6(2) is 09 and UDATE+0(4) is 2022. First add 30 and '.' and after add 12 and '.' and 2022 and after add, All that can store into the CDATE variable.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top