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 convert the date format??

Former Member
0 Likes
1,020

Hi All,

I have an internal table with a field 'fdate'.The date comes in this field in the format 'Apr292008'.

Now I want this date to be converted into '04292008' format.

Is There any means to do this.

Or is there any function module to do so??

Kindly suggest.

Thank You.

Hi All,

I have an internal table with a field 'fdate'.The date comes in this field in the format 'Apr292008'.

Now I want this date to be converted into '04292008' format.

Is There any means to do this.

Or is there any function module to do so??

Kindly suggest.

Thank You.

6 REPLIES 6
Read only

Former Member
0 Likes
976

Hi Rohan,

Try this FM

CONVERT_DATE_TO_EXTERNAL

Converts date from system storage format to users specified display format .

Reward if helpfull :):)

Read only

Former Member
0 Likes
976

Hi,

You write one case statements for each month & modify with respective month number.

Like as follows.

DATA : DATE(9).

DATA : VAR(3).

DATA : VAR1(2) TYPE N.

DATE : 'Apr292008'.

VAR = DATE+(3).

CASE VAR.

WHEN 'JAN.

VAR1 = '01'.

.......

.........

ENDCASE.

AND CONCATENATE THE MONTH NUMBER WITH YOUR DATE

IT WILL WORK.

regards,

Madan.

Read only

Former Member
0 Likes
976

The Simplest way is to go with the below logic.



" fdate will contain date in MMMDDYYYY format

l_date = fdate+0(3).

case l_date.
  when 'Jan': l_mon = '01'.
  when 'Feb': l_mon = '02'. 
  when 'Mar': l_mon = '03'. 
  when 'Apr': l_mon = '04'. 
  when 'May': l_mon = '05'. 
  when 'Jun': l_mon = '06'. 
  when 'Jul': l_mon = '07'. 
  when 'Aug': l_mon = '08'. 
  when 'Sep': l_mon = '09'. 
  when 'Oct': l_mon = '10'. 
  when 'Nov': l_mon = '11'. 
  when 'Dec': l_mon = '12'. 
endcase.

concatenate l_mon fdate+3 into l_fdate.


" l_fdate will contain the date in MMDDYYYY format.

Hope this helps.

Thanks,

Balaji

Read only

Former Member
0 Likes
976

HI,

use the code in internal table like below.


TABLES:t015m.
DATA:dat(15) VALUE 'Apr292008'.
DATA:mon(2).

SELECT * FROM t015m WHERE spras = 'E'.
  TRANSLATE dat(3) to upper case.
  TRANSLATE t015m-monam(3) to upper case.
  IF t015m-monam(3) = dat(3).
    mon = t015m-monum.
    exit.
  ENDIF.
ENDSELECT.

CONCATENATE mon dat+3 INTO dat.

write:/ dat.

rgds,

bharat.

Read only

Former Member
0 Likes
976

Hi,

Use these function modules

CONVERT_DATE_BY_PERIOD_INPUT

CONVERT_DATE_BY_PERIOD_OUTPUT

It will usefull try once.

First use convert_date_input

After use convert_date_by_period_output.

it wil get output in your format from apr292008 to 04.29.2008.

*reward points

Edited by: jeevitha on May 6, 2008 10:22 AM

Read only

Former Member
0 Likes
976

Try this sample code:

DATA: str(9) VALUE 'Apr292008'.

DATA: mon1(3).

DATA: mon(2).

WRITE: /1 str.

translate str+0(3) TO UPPER CASE.

mon1 = str+0(3).

SELECT SINGLE mnr FROM t247 INTO mon WHERE ktx EQ mon1 AND spras EQ sy-langu.

REPLACE FIRST OCCURRENCE OF mon1 IN str WITH mon.

WRITE: /1 str.