Application Development 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: 

to change the date format

Former Member
0 Kudos

hi experts

my problem is to change the date format.actualy the input is 14.10.2008 but i have to change this format like 20081014.so ple give me some code.the output is 20081014. ple adjunt

5 REPLIES 5

Former Member
0 Kudos

USE FUNCTION MODULE :

FORMAT_DATE_4_OUTPUT
DATIN =14.10.2008
FORMAT = YYYY/MM/DD

Former Member
0 Kudos

Hi,

data : date type sy-datum,

var1 type char 15.

initialization.

date = sy-datum.

end of selection.

concatenate date0(4) date4(2) date+6(2) into var1.

write var1.

former_member585060
Active Contributor
0 Kudos

Hi,

SAP internal format will be 20081014 type what ever you give in different format, you can check that in Debugging mode and give SY-DATUM, it will display the format in which you want.

Do you want that to display in OUTPUT, do that using Concatenate statement. declaring 3 fields, and use officet to read the values.

Regards

Bala Krishna

Former Member
0 Kudos

Hi,

Use the FM CONVERT_DATE_TO_INTERNAL;

Data : date_in(10) type c,
       date_out type d.

date_in = '14.10.2008'.
BREAK-POINT.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
  EXPORTING
    date_external                  = date_in
 IMPORTING
   DATE_INTERNAL                  = date_out
 EXCEPTIONS
   DATE_EXTERNAL_IS_INVALID       = 1
   OTHERS                         = 2.

date_out will have date in format 20081014.

Regards

Karthik D

Former Member
0 Kudos

Hi Sree,

What Karthik wrote was correct. May be you directly used WRITE stmt for the output.

Karthik i am modifing your code a bit.

Sree try this out

Data : date_in(10) type c,
       date_out type d.

DATA : DATE_FORMATTED TYPE CHAR10.

date_in = '14.10.2008'.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
  EXPORTING
    date_external            = date_in
  IMPORTING
    DATE_INTERNAL            = date_out
  EXCEPTIONS
    DATE_EXTERNAL_IS_INVALID = 1
    OTHERS                   = 2.

DATE_FORMATTED = date_out.

WRITE date_formatted.

Regards

Edited by: Rajvansh Ravi on Oct 17, 2008 6:41 AM