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: 

Date format conversion

Former Member
0 Kudos

Hi,

I would like to convert date from any format to YYYYMM.

Could any one suggest me how to go about?

1 ACCEPTED SOLUTION

athavanraja
Active Contributor
0 Kudos

system keeps the dates in YYYYMMDD format (as long as the field is of type D). so you dont have to do anything special to convert. in your case you wanted YYYYMM which is bascially offsetting for which you can follow the answers given by others in the thread.

Regards

Raja

6 REPLIES 6

Former Member
0 Kudos

Hi,

Pl use the function module

CONVERT_DATE_TO_INTERN_FORMAT

Else

You declare the target field as type date, and directly move your source field into the target, SAP will automatically convert the target into internal format.

Regards

Elini.P

Former Member
0 Kudos

Hi,

Try this

WRITE: sy-datum,

/ sy-datum yymmdd.

Thanks&Regards,

Ruthra

Former Member
0 Kudos

Hi Anu,

its very much possible , but you must know whath the date format is given to you as input.

for example if its like sy-datum (YYYYMMDD).

you simply have to store the first six digit of the date into strng type variable:

data: input_date like sy-datum value '20051231'. "31st dec of 2005

data: str(6).

str = input_date(6).

write str.

thats it. you also can use some mask like ____/__/ for another solution. but you must do the coding specific to input format. that is if its YYYYMMDD your code will be as i have given, but if it is YYYYDDMM or DDMMYYYY, the code will be diffrent. there is no generic solution i think.

Former Member
0 Kudos

use function module CONVERT_DATE_TO_INTERNAL

and then read the first 6 characters...

eg:

DATA l_date(10) TYPE c.

DATA lt TYPE sy-datum.

l_date = '24.10.2005'.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = l_date

IMPORTING

date_internal = lt

EXCEPTIONS

DATE_EXTERNAL_IS_INVALID = 1

OTHERS = 2

.

WRITE 😕 lt+0(6).

rgds,

PJ

Message was edited by: Priyank Jain

athavanraja
Active Contributor
0 Kudos

system keeps the dates in YYYYMMDD format (as long as the field is of type D). so you dont have to do anything special to convert. in your case you wanted YYYYMM which is bascially offsetting for which you can follow the answers given by others in the thread.

Regards

Raja

Former Member
0 Kudos

hi,

use can use the function modules mentioned above or use

the concatenate statement.

eg. date entered in format yyyymmdd say 20051024

data : w_date like sy-datum.

CONCATENATE w_date0(4) w_date4(2) iNTO w_date.

Hope this helps.

regards,

kavita joshi.