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

To Change date format

Former Member
0 Likes
1,438

Hi,

I have a requiremnt where i need to change the date format to yyyymmdd..I have treid using the WRITE TO statement but it didn't work.

suppose i got the field value as 05082008(ddmmyyyy), i need to write as (20080805)(yyyymmdd).

I tried the bewlo statemnt.

write : lv_date1 to lv_date yymmdd.It didn't worked..

can anyone suggest me.

Regards,

Raj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,406

hi,

use offset and get day, month and year seperately..

then use concatenate to get output in desired format.

Rgds.,

subash

Hi,

I have a requiremnt where i need to change the date format to yyyymmdd..I have treid using the WRITE TO statement but it didn't work.

suppose i got the field value as 05082008(ddmmyyyy), i need to write as (20080805)(yyyymmdd).

I tried the bewlo statemnt.

write : lv_date1 to lv_date yymmdd.It didn't worked..

can anyone suggest me.

Regards,

Raj

7 REPLIES 7
Read only

Former Member
0 Likes
1,407

hi,

use offset and get day, month and year seperately..

then use concatenate to get output in desired format.

Rgds.,

subash

Read only

0 Likes
1,406

Hi,

I also done that but there is a problem with the user's own data..It may change from user to user...

for one user am getting yyyyddmm and for one user am getting yyyymmdd..In this case how to offset the values and conncatenate to get the format as yyyymmdd.

Regards,

raj

Read only

0 Likes
1,406

Kumar,

Pass the username to USR01 table and check DATFM field...

this DATFM field will have the data format details for a given user.

say 1-> for DDMMYYYY and 2 for -->YYYYMMDD etc.,

Based on these you can write ur code for concatenation

example:

if datfm = 2.

concatenate sy-datum0(4) sy-datum4(2) sy-datum+6(2) into v_date.

endif.

Regards,

Aswin.

Read only

0 Likes
1,406

Hi,

I had done small change in the code reagrding the offsetting and it worked...

Regards,

Raj

Read only

0 Likes
1,406

try like this...

data : date(8).

data: d1(8)."[this is ur date field]

date0(4) = d1 0(4)."yyyy

date4(2) = d1 4(2)."mm

date6(2) = d16(2). "dd

write: / date.

change offset accordindly.

Read only

0 Likes
1,406

Hi,

first u get the user data format from USR01 table field DATFM, then u do the CONCATENATION bassed on the format..

eg:

**To Know the Date Format for the user name in user master record

SELECT SINGLE datfm FROM usr01

INTO v_datfm

WHERE bname = sy-uname.

CASE v_datfm.

WHEN 1.

CONCATENATE it_final-vdatu3(2) '.' it_final-vdatu0(2) '.' it_final-vdatu+6(4) INTO it_final-vdatu.

WHEN 2.

CONCATENATE it_final-vdatu0(2) '/' it_final-vdatu3(2) '/' it_final-vdatu+6(4) INTO it_final-vdatu.

WHEN 3.

CONCATENATE it_final-vdatu0(2) '-' it_final-vdatu3(2) '-' it_final-vdatu+6(4) INTO it_final-vdatu.

WHEN 4.

CONCATENATE it_final-vdatu6(4) '.' it_final-vdatu0(2) '.' it_final-vdatu+3(2) INTO it_final-vdatu.

WHEN 5.

CONCATENATE it_final-vdatu6(4) '/' it_final-vdatu0(2) '/' it_final-vdatu+3(2) INTO it_final-vdatu.

WHEN 6.

CONCATENATE it_final-vdatu6(4) '-' it_final-vdatu0(2) '-' it_final-vdatu+3(2) INTO it_final-vdatu.

endcase.

Regards,

Pavan

Read only

Former Member
0 Likes
1,406

Hi,

Use FM CONVERT_DATE_TO_INTERNAL.

Regards,

Raju.