I know that you are required convert system date format to user required date format with out using function module.
Example - 1 : SY-DATUM or DD . MM . YYYY To DD
Example - 2 : SY-DATUM or DD . MM . YYYY To MM
Example - 3 : SY-DATUM or DD . MM . YYYY To YYYY
Example - 4 : SY-DATUM or DD . MM . YYYY To DD - MM - YYYY
Example - 5 : SY-DATUM or DD . MM . YYYY To DD / MM / YYYY
Example - 6 : SY-DATUM or DD . MM . YYYY To YYYY / MM / DD
Example - 7 : SY-DATUM or DD . MM . YYYY To MM / DD / YYYY
Example - 8 : SY-DATUM or DD . MM . YYYY To Current year / Next year
Example - 9 : YYYYMMDD To DD . MM . YYYY
Example - 10 : YYYYDDMM To DD . MM . YYYY
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) that means after 4 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 - 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
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
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.
0 Comments