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

date conversion

Former Member
0 Likes
799

i want to conert date to following format

20070101 = in 1st January 2007

what should i do

is there any function module

6 REPLIES 6
Read only

prasanth_kasturi
Active Contributor
0 Likes
753

Try this function module.

CONVERSION_EXIT_SDATE_OUTPUT

or

CONVERSION_EXIT_IDATE_OUTPUT

Use CONVERSION_EXIT_SDATE_OUTPUT to get the month name,

but it will give short form of the month name.

if you want long description of the month,

use this peice of code.

PARAMETERS: V_DATUM(07) TYPE C. "(example input:12-2007)

DATA: V_MON(2) TYPE C,

V_YEAR(4) TYPE C,

V_MONTHNAME(10) TYPE C,

V_FULLDATE(30) type c.

WRITE V_DATUM+0(2) TO V_MON.

SELECT SINGLE LTX FROM T247 INTO V_MONTHNAME

WHERE SPRAS = SY-LANGU

AND MNR = V_MON.

CONCATENATE V_MONTHNAME v_datum+3(4)

INTO V_FULLDATE SEPARATED BY SPACE. "(example output : December 2007)

write: v_fulldate.

reward if helpful

regard

prasanth

Read only

Former Member
0 Likes
753

Hi,

for this u need to write ur own code.


PARAMETERS:dat like sy-datum.

DATA:day(2),month(2),year(4),month_text(10),output(20).
day = dat+6.
month = dat+4.
year = dat.

PERFORM get_month_text using month.

CONCATENATE day month_text year into output SEPARATED BY space.

write:/ output.

FORM get_month_text  USING    P_MONTH.
  CASE p_month.
    WHEN 1.
      month_text = 'January'.
    WHEN 2.
      month_text = 'February'.
    WHEN 3.
      month_text = 'March'.
    WHEN 4.
      month_text = 'April'.
    ....
    ....
    WHEN 12.
      month_text = 'December'.
  ENDCASE.
ENDFORM.                    " get_month_text

rgds,

bharat.

Read only

0 Likes
753

Hi, USE THE CODE AS BELOW :

data : output(30).

data: input(50) type c.

input = '20070101'.

CALL FUNCTION 'CONVERSION_EXIT_SDATE_OUTPUT'

EXPORTING

input = input

IMPORTING

OUTPUT = output.

write : output.

Reward points, if helpful,

Sandeep Kaushik

Read only

Former Member
0 Likes
753

Hi,

Try this code.

data: date1(15),

date2(15).

*CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'

  • EXPORTING

  • input = sy-datum

  • IMPORTING

  • OUTPUT = date1

  • .

*write:/ date1.

*write:/ date1 using edit mask '__ ___ ____'.

*concatenate date10(2) date12(3) date1+5 into date2 separated by

*space.

*write:/ date2.

OR

CALL FUNCTION 'CONVERSION_EXIT_SDATE_OUTPUT'

EXPORTING

input = sy-datum

IMPORTING

OUTPUT = date1

.

write:/ date1.

Reward,if useful.

Thanks,

Chandu

Read only

former_member784222
Active Participant
0 Likes
753

There is no standard FM to do that for you.

Your approach should be to determine the month text from table t247 and write the date as:

date6(2) <st><nd><rd><th> , Monthtext Ydate0(4).

st - for dates ending with 1,

nd- for dates ending with 2,

rd-for dates ending with 3,

th-for others.

regards,

Mouli.

Read only

Former Member
0 Likes
753

Hi,

Use the below code.

PARAMETERS: p_date TYPE sy-datum DEFAULT sy-datum.

DATA: v_month(30),

v_day(2),

v_day_text(4),

month_names LIKE t247 OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'MONTH_NAMES_GET'

EXPORTING

language = sy-langu

TABLES

month_names = month_names

EXCEPTIONS

month_names_not_found = 1

OTHERS = 2.

READ TABLE month_names WITH KEY spras = 'E'

mnr = p_date+4(2).

IF sy-subrc = 0.

v_month = month_names-ltx.

ENDIF.

v_day = p_date+6(2).

case v_day.

when '01' or '21' or '31'.

v_day_text = 'st'.

when '02' or '22'.

v_day_text = 'nd'.

when '03' or '23'.

v_day_text = 'rd'.

when others.

v_day_text = 'th'.

endcase.

if v_day+0(1) = '0'.

shift v_day.

endif.

concatenate v_day v_day_text into v_day_text.

CONCATENATE v_day_text v_month p_date+0(4) INTO v_month separated

by space.

WRITE:/ v_month.