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

Convert Date format

former_member764673
Participant
0 Likes
1,177

Hi all,

I am having data value like 31-JUL-06, i want to convert this to YYYYMMDD format. Is there any FM to achieve this.

Thanks & Regards,

Rajanidhi Rajasekeran.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,089

This will solve ur problem

Use these function module

25-APR-06.. separator here should be in ur own system format

CONVERSION_EXIT_SDATE_INPUT

to convert to sy-datum format..

Regards,

Viven

9 REPLIES 9
Read only

Former Member
0 Likes
1,089

Hi,

You can use edit mask to do the same, for ex,

DATA : LV_DATUM(10).

WRITE V_DAT TO LV_DATUM USING EDIT MASK '__.__.____'.

Hope this helps,

Rgds,

Read only

Former Member
0 Likes
1,089

Hi rajanidhi,

1. we can use the FM

CONVERSION_EXIT_SDATE_INPUT

2. some minor logic will be reqruied,

bcos it accpets date in this format

31JUL2006

(and not 31-JUL-2006 with hiphen)

regards,

amit m.

Read only

Former Member
0 Likes
1,089

This is nothing but the internal format of SAP, so you can use function CONVERT_DATE_TO_INTERNAL to do that.

Regards,

Ravi

Note : Please mark all the helpful answers

Read only

Former Member
0 Likes
1,090

This will solve ur problem

Use these function module

25-APR-06.. separator here should be in ur own system format

CONVERSION_EXIT_SDATE_INPUT

to convert to sy-datum format..

Regards,

Viven

Read only

Former Member
0 Likes
1,089

Hi rajanidhi,

Use this FM CONVERSION_EXIT_SDATE_INPUT.It will accept the date in the format 13JUL2005 and will give the date in the format 20051307.Use this FM and format the output as per your requirement.

Regards,

Mukesh Kumar

Read only

Former Member
0 Likes
1,089

Hi Rajanidhi

Refer to the following FMs

<b>CONVERT_DATE_TO_INTERN_FORMAT </b> Converts a date to internal format

<b>CONVERT_DATE_TO_EXTERNAL </b> Conversion: Internal to external date (like screen conversion)

<b>CONVERT_DATE_TO_INTERNAL </b> Conversion: External to internal date (like screen conversion)

<b>CONVERT_DATE_INPUT </b> Conversion of a date from external to internal format

<b>CONVERT_DATE_WITH_THRESHOLD</b> Date conversion from external to internal format with time threshold

<b>CONVERT_DATE_BY_PERIOD_INPUT</b>

<b>CONVERT_DATE_BY_PERIOD_OUTPUT </b>

Regards

Inder

Read only

Former Member
0 Likes
1,089

Hi,

Consider this code,


REPORT  zztest_prd_1                            .


DATA : temp TYPE sy-datum,
       odate(8).


PARAMETERS : idate(11) TYPE c DEFAULT '31-JUL-06'.


START-OF-SELECTION.

  TRANSLATE :  idate TO UPPER CASE,
               idate USING '- '.

  CONDENSE idate NO-GAPS.

  CONCATENATE idate+0(5) sy-datum+0(4) INTO idate.


  BREAK-POINT.

  CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'
    EXPORTING
      input  = idate
    IMPORTING
      output = temp.


  CONCATENATE temp+0(4) temp+6(2) temp+4(2) INTO odate.

  WRITE : /10  idate,
          /10  odate .

Regards,

AS

Read only

0 Likes
1,089

use fm..

<b>CONVERSION_EXIT_SDATE_INPUT</b>

Read only

Former Member
0 Likes
1,089

HI Rajanidhi,

Plz check this code once.

VALIDATE DATE

temp_date = in_date.

call function 'DATE_CHECK_PLAUSIBILITY'

exporting

date = temp_date

exceptions

plausibility_check_failed = 1

others = 2.

if sy-subrc <> 0.

raise invalid_date.

exit.

endif.

  • RETRIEVE USER PROFILE DATE SETTING

select single datfm

into user_setting

from usr01

where bname = sy-uname.

  • REFORMAT DATE ACCORDING TO USER PROFILE

case user_setting.

when '1'.

out_date(2) = in_date+6(2).

out_date2(2) = in_date4(2).

out_date+4(4) = in_date(4).

when '2' or '3'.

out_date(2) = in_date+4(2).

out_date2(2) = in_date6(2).

out_date+4(4) = in_date(4).

when '4' or '5' or '6'.

out_date = in_date.

endcase.

Regards,

Sudha.