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: 
Read only

How to change the date format YYYYMMDD to MM/DD/YYYY

Former Member
59,358

Hi ,

How to change the date format YYYYMMDD to MM/DD/YYYY .

Ex : 20071008 to 10/08/2007

Is there any function module for this ??

Regards

Rahul

1 ACCEPTED SOLUTION
Read only

Former Member
17,810

You can use the offset

date(4) is year

date+4(2) is month

date+6(2) is day

use concatenate date4(2) '/' date6(2) '/' date(4) into field date_result.

REWARD POINTS IF USEFULL.

Khusro Habib

14 REPLIES 14
Read only

Former Member
0 Likes
17,810

Hi,

you can use edit mask 'yyyymmdd'.

or

data : odate(12) value '13-JUL-2007',

idate like sy-datum,

odate1(10).

replace all occurrences of '-' in odate with space.

CALL FUNCTION 'CONVERSION_EXIT_IDATE_INPUT'

EXPORTING

INPUT = odate

IMPORTING

OUTPUT = idate

.

CALL FUNCTION 'CONVERSION_EXIT_PDATE_OUTPUT'

EXPORTING

INPUT = idate

IMPORTING

OUTPUT = odate1

.

write : / odate1.

Thanks.

Reward If Helpful.

Read only

Former Member
0 Likes
17,810

hi ,

For this, you will have to get the onscreen date in a string or a charcter of length 10 and then pass it to the FM, CONVERT_DATE_TO_INTERNAL and the output will be of the yyyymmdd format....

plz reward if useful..

Read only

Former Member
17,811

You can use the offset

date(4) is year

date+4(2) is month

date+6(2) is day

use concatenate date4(2) '/' date6(2) '/' date(4) into field date_result.

REWARD POINTS IF USEFULL.

Khusro Habib

Read only

amit_khare
Active Contributor
0 Likes
17,810

data v_date type char10.

concatenate sy-datum4(2) sy-datum6(2) sy-datum+0(4) into v_date separated by '/'.

Read only

Former Member
17,810

Hi,

Try like this:

v_date = '20071008'.

zyy = v_date+0(4).

zmm = v_date+4(2).

zdd = v_date+6(2).

concatenate zmm '/' zdd '/' zyy into zdate.

write zdate.

Regards,

Bhaskar

Read only

abdulazeez12
Active Contributor
0 Likes
17,810

You can use the offsets..

For example, if ur date variabel gv_date contains value 20071008 ( if u kow it is of YYYYMMDD format).

declare another varable gv_date1(8) type c

gv_date14(4) = gv_date0(4)

gv_date10(2) = gv_date4(2)

gv_date12(2) = gv_date6(2)

finally, gv_date1 will have MMDDYYY format

Read only

Former Member
0 Likes
17,810

Hi,

odate(10) type c.

write sy-datum to odate. " this will take care ur requirement.

Read only

Former Member
0 Likes
17,810

Hi,

The function module to convert the date format from YYYYMMDD to MMDDYYYY is :

<b>CONVERT_DATE_TO_INTERNAL</b>

This Function Module will convert date as the internal format.

Regards,

Padmam.

Read only

Former Member
0 Likes
17,810

hi

try this coding

data : d1(8) type c value '20071008',

d2(10) type c.

CONCATENATE d14(2) '/' d16(2) '/' d1+0(4)

INTO d2.

write : d2.

and one more thing u can chage the directly through the transaction

SU3.

regards

baskaran

Read only

Former Member
0 Likes
17,810

Hi,

u can change it using a key word called EDIT_MASK .

if u want permanet chnage.

System->user Profile->own data

Assign points if useful.

Regards

(YUGANDHAR.P)

Read only

Former Member
0 Likes
17,810

Hi Sharma,

check the code:

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-031.

PARAMETERS: date1 RADIOBUTTON GROUP rad1 DEFAULT 'X', "SAP date format YYYYDDMM

date2 RADIOBUTTON GROUP rad1, "Date format like aprial31, 2006

date3 RADIOBUTTON GROUP rad1, "Date format like 31 apr,2006

date4 RADIOBUTTON GROUP rad1, "Date format like DD/MM/YYYY

date5 RADIOBUTTON GROUP rad1. "Date format like DD.MM.YYYY

SELECTION-SCREEN END OF BLOCK b2

FORM getmonth .

SELECT mnr

ktx

ltx

INTO TABLE T_month

FROM t247

WHERE spras = 'EN'.

IF sy-subrc NE '0'.

MESSAGE I "Message - Not able to get month values from the table T247

ENDIF.

ENDFORM.

DATA : temp_date(16) TYPE c,

temp1_date(60) TYPE c,

year(4) TYPE c,

daymonth(11) TYPE c,

daymonth1(11) TYPE c,

month(9) TYPE c,

day(2) TYPE c,

mon LIKE t247-ktx,

len TYPE i .

MOVE date TO temp1_date .

CONDENSE temp1_date NO-GAPS.

MOVE temp1_date TO temp_date .

IF date2 EQ 'X'. "The date format is like Aprial 31, 2007

CONDENSE temp_date NO-GAPS.

SPLIT date AT ',' INTO daymonth year.

IF STRLEN( year ) NE '4'.

error = 'X'.

WRITE : 'Invalid date format.'.

ELSE.

daymonth1 = daymonth.

CONDENSE daymonth1 NO-GAPS.

_len = STRLEN( _daymonth1 ).

l_len = 13 - len.

SHIFT daymonth1 RIGHT BY len PLACES.

CONDENSE daymonth1 NO-GAPS.

month = daymonth1.

CONDENSE month NO-GAPS.

SORT t_month BY monthltx.

READ TABLE t_month WITH KEY monthltx = month.

IF sy-subrc <> 0.

error = 'X'.

WRITE : 'Invalid date format.' .

ELSE.

len = STRLEN( month ).

CONDENSE daymonth NO-GAPS.

SHIFT daymonth LEFT BY len PLACES.

day = daymonth.

CONDENSE day NO-GAPS.

CONCATENATE year t_month-monthnumber day INTO o_date.

ENDIF.

ENDIF.

ELSEIF p_date3 EQ 'X'. "The date format is like 31 apr, 2007

CONDENSE temp_date NO-GAPS.

SPLIT i_date AT ',' INTO daymonth year.

IF STRLEN( year ) NE '4'.

error = 'X'.

WRITE : 'Invalid date format.'.

ELSE.

daymonth1 = daymonth.

CONDENSE daymonth1 NO-GAPS.

SHIFT daymonth1 LEFT BY 2 PLACES.

CONDENSE daymonth1 NO-GAPS.

month = daymonth1.

CONDENSE month NO-GAPS.

TRANSLATE month TO UPPER CASE.

SORT t_month BY monthstx.

MOVE month to mon.

READ TABLE t_month WITH KEY monthstx = mon.

IF sy-subrc <> 0.

error = 'X'.

WRITE : 'Invalid date format.' .

ELSE.

CONDENSE daymonth NO-GAPS.

day = daymonth+0(2).

CONDENSE day NO-GAPS.

CONCATENATE year t_month-monthnumber day INTO o_date.

ENDIF.

ENDIF.

ELSEIF p_date4 EQ 'X' OR p_date5 EQ 'X'. "Date format is like DD.MM.YYYY or DD/MM/YYYY

CONDENSE temp_date NO-GAPS.

IF STRLEN( temp_date ) EQ 10.

o_date0(4) = temp_date6(4).

o_date4(2) = temp_date3(2).

o_date6(2) = temp_date0(2).

ELSE.

error = 'X'.

WRITE : 'Invalid date format.' .

ENDIF.

ENDIF.

IF STRLEN( o_date ) NE '8'.

error = 'X'.

WRITE : 'Invalid date format.'.

ENDIf.

ENDFORM. " f0100_conv_date

Reward if helpful.

Regards,

Harini.S

Read only

Former Member
0 Likes
17,810

solved

Read only

marcus_brbara
Discoverer
0 Likes
17,810

WRITE |{ sy-datum }| USING EDIT MASK 'RR____/__/__' TO DATA(result).

Read only

marcus_brbara
Discoverer
0 Likes
17,810

cl_abap_datfm=>conv_date_int_to_ext(

EXPORTING
im_datint = sy-datum
im_datfmdes = '2'
IMPORTING
ex_datext = DATA(ex_datext)
).