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

Function module for date conversion

Former Member
0 Likes
28,011

Hi,

Is there any standard FM to convert data format:

Sample input/output is:

Input: 02-Feb-2009

Output: 20090202

Thanks,

Neelima.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
15,211

Hi,

Please use this Function Module

CONVERSION_EXIT_SDATE_INPUT

for ex:

Give input = 01.FEB.2007

then the output wil be = 20070201

Thanks

Murugan.B

11 REPLIES 11
Read only

Former Member
0 Likes
15,211

Hi,

You can try the following FMs

DATE_CONV_EXT_TO_INT - Conversion of dates to SAP's internal format

CONVERT_DATE_TO_INTERNAL - Formats date from display to internal format

But better you write code...that is with corresponding numbers such as (Jan = 01, Feb = 02, and so on...) and then concatenate into the system date.

Simply SPLIT the <input date> at "-" into <day> , <month> and <year>.

Then convert the <month> to numbers accordingly..

Then CONCATENATE them in the order you want.

Regards.

Edited by: rajan roy on Mar 5, 2009 1:38 PM

Read only

Former Member
0 Likes
15,212

Hi,

Please use this Function Module

CONVERSION_EXIT_SDATE_INPUT

for ex:

Give input = 01.FEB.2007

then the output wil be = 20070201

Thanks

Murugan.B

Read only

0 Likes
15,211

Hi,

Thanks, but by replacing '-' with '.' this is working

input : 20-feb-2009 is not working only 20.feb.2009 is working.

Thanks,

Neelima

Read only

0 Likes
15,211

Check the user setting as I have mentioned in earlier post. You need to change the default for date n re-login.

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
15,211

hi,

DATA : wa_date(12) VALUE '02-Feb-2009', "dd-mmm-yyyy
       wa_day(2),
       wa_mth(3),
       wa_yer(4),
       wa_date1(8), "yyyymmdd
       wa_mnr(2).

SPLIT wa_date AT '-' INTO wa_day
                          wa_mth
                          wa_yer.

TRANSLATE wa_mth TO UPPER CASE.

SELECT SINGLE mnr FROM t247 INTO wa_mnr WHERE ktx = wa_mth
                                        AND   spras = sy-langu.

CONCATENATE wa_yer  wa_mnr wa_day INTO wa_date1.
"output : 20090202

Read only

Former Member
0 Likes
15,211

Hi Neelima,

For your requirement,

First you need to use the function module

CONVERSION_EXIT_SDATE_INPUT

Internally

Input = 01.FEB.2007 
Output wil be = 20070201

All you need to do is move this output date to a variable. 

Data : v_dat type sy-datum. 

  v_dat = 20070201.

After that you need to use another function module calle 


CONVERT_DATE_TO_INTERNAL 

IMport parameter 

You need to pass this variable into Import parameter ->  v_dat


So that you will get the output of the date format as you want

Regards,

Kittu

Read only

Former Member
0 Likes
15,211

Hi,

Try the FM : CONVERSION_EXIT_SDATE_INPUT (or)

Check with the below code:

DATA : wa_date(40) VALUE 'February 02, 2009',

wa_date1(10),

var1(15),

var2(3),

var3(4),

month(2).

SPLIT wa_date AT space INTO var1 var2 var3.

SELECT SINGLE mnr FROM t247 INTO month WHERE spras = sy-langu AND ltx

= var1.

CONCATENATE month var2+0(2) var3 INTO wa_date1 SEPARATED BY '/'.

WRITE wa_date1.

Regards,

Shalini

Edited by: shalini reddy on Mar 5, 2009 2:44 PM

Read only

Former Member
0 Likes
15,211

Hi,

Before using fm CONVERSION_EXIT_SDATE_INPUT for date conversion you need to first check the default date format for your user profile in SAP. It needs to be MM-DD-YYYY to cater for your requirement. To do this follow these steps :

1 ) Navigate to System->User Profile -> Own Data

2 ) Click on Defaults tab

3 ) Change the date format to DD-MM-YYYY and save.

4 ) Log Off and Re-Login to the SAP system.

Now you can use fm CONVERSION_EXIT_SDATE_INPUT to change the date format.

Input : 02-FEB-2009

Output : 20090202

Hope it helps.

Reg

Ashwani

Read only

naveen_inuganti2
Active Contributor
0 Likes
15,211

Neelima,

[ABAP Function Modules for Date Conversions|https://wiki.sdn.sap.com/wiki/display/ABAP/ABAPFunctionModules]

Search for the correct one.,

Thanks,

Naveen Inuganti.

Read only

Former Member
0 Likes
15,211

Hi,

check this fm

CONVERSION_EXIT_INVDT_OUTPUT

Thanks and regrds

Durga.K

Read only

Former Member
0 Likes
15,211

I have provided the FM as well as the code in the your previous thred with different subject line yesterday.

Pooja