cancel
Showing results for 
Search instead for 
Did you mean: 

Date format from mm/dd/yyyy to dd-mmm-yyyy

Former Member
0 Kudos

How to convert the date from 01/01/2006 to 01-Jan-2006??

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use function module CONVERSION_EXIT_SDATE_OUTPUT to convert the date format.

With Regards,

Nelson

Answers (5)

Answers (5)

former_member186078
Active Participant
0 Kudos

Hi Sravanthi,

It would be better if you go for any standard function module for these kind of purposes instead of writing our own logic, because, they will take care of the validations also.

My idea, is to go with the Nelson's solution itself. You can use that function module, it will work perfectly. But the only thing, you require here is you need to pass the INPUT value in the format YYYYMMDD, which is not a big deal, coz that can be done so easily based upon the user settings format.

Use the function modules in the following order:

CONVERSION_EXIT_PDATE_INPUT

And pass the output we get from this function module to the CONVERSION_EXIT_SDATE_OUTPUT.

Here, the first one will convert from the User setting dte format i.e., it can be mm/dd/yyyy or mm.dd.yyyy or dd/mm/yyyy . It will directly convert it to the YYYYMMDD format and the second one will give you, your required output.

  • Note: If the answer is helpful, plz reward points for it.

Former Member
0 Kudos

Hi Sravanthi,

See the following code.

REPORT zpgm1.

PARAMETER: x TYPE dats.

DATA: y(11) TYPE c.

CASE x+4(2).

WHEN '01'.

CONCATENATE x6(2) '-' 'Jan' '-' x0(4) INTO y.

WHEN '02'.

CONCATENATE x6(2) '-' 'Feb' '-' x0(4) INTO y.

WHEN '03'.

CONCATENATE x6(2) '-' 'Mar' '-' x0(4) INTO y.

WHEN '04'.

CONCATENATE x6(2) '-' 'Apr' '-' x0(4) INTO y.

WHEN '05'.

CONCATENATE x6(2) '-' 'May' '-' x0(4) INTO y.

WHEN '06'.

CONCATENATE x6(2) '-' 'Jun' '-' x0(4) INTO y.

WHEN '07'.

CONCATENATE x6(2) '-' 'Jul' '-' x0(4) INTO y.

WHEN '08'.

CONCATENATE x6(2) '-' 'Aug' '-' x0(4) INTO y.

WHEN '09'.

CONCATENATE x6(2) '-' 'Sep' '-' x0(4) INTO y.

WHEN '10'.

CONCATENATE x6(2) '-' 'Oct' '-' x0(4) INTO y.

WHEN '11'.

CONCATENATE x6(2) '-' 'Nov' '-' x0(4) INTO y.

WHEN '12'.

CONCATENATE x6(2) '-' 'Dec' '-' x0(4) INTO y.

ENDCASE.

WRITE:/ x.

WRITE:/ y.

You can use the above logic to convert the date.

But check the System date format before using this logic.

Regards,

Vaitheeswaran

Former Member
0 Kudos

HI

GOOD

CHECK THIS WITH YOUR REQUIREMENT.

CONVERT

Variants

1. CONVERT DATE f1 INTO INVERTED-DATE f2.

2. CONVERT INVERTED-DATE f1 INTO DATE f2.

Effect

Allows conversion between different formats which do not have their own type (see also MOVE ).

The field f1 is converted from the source format to the target format and placed in f2 .

At present, the following formats are supported:

DATE ==> INVERTED-DATE INVERTED-DATE ==> DATE

Both formats form the nine's complement of internal date representation, e.g. 19950511 ==> 80049488 or 80049488 ==> 19950511. In inverse date format, the most recent date has the lowest numerical value. This is useful when sorting date specifications.

Note

The technique of modifying the sequence of dates by inverting the internal date format is only used in very rare cases. For example, you can sort internal tables in ascending or descending date order much more elegantly with the additons ... ASCENDING bzw. ... DESCENDING of the SORT statement.

Example

DATA DATE_INV LIKE SY-DATUM.

CONVERT DATE SY-DATUM INTO INVERTED-DATE DATE_INV.

If, for example, the internal representation of 11.05.95 in SY-DATUM is 19950511, the value of DATE_INV after execution of the CONVERT statement is 80049488.

Note

Runtime errors

CONVERT_ILLEGAL_CONVERSION : Conversion not possible due to incorrect field length.

GO THROUGH THIS LINK

http://www.sap4.com/contentid-130.html

THANKS

MRUTYUN

Former Member
0 Kudos

Hi sravanthi,

1. we have to apply some logic for that,

and use the standard FM

'MONTH_NAMES_GET'

2. i have an independent FORM/PERFORM

in which we give input as some date,

and it returns date in format

dd-mon-yyyy.

3. just copy paste in new program and run.

report abc.

DATA : mname(25) TYPE c.

PARAMETER : d TYPE sy-datum default sy-datum.

PERFORM getmonth USING d mname.

WRITE 😕 mname.

*----


*

*----


FORM getmonth USING d mname.

DATA : month_names LIKE t247 OCCURS 0 WITH HEADER LINE.

DATA : m(2) TYPE c.

m = d+4(2).

CALL FUNCTION 'MONTH_NAMES_GET'

  • EXPORTING

  • LANGUAGE = SY-LANGU

  • IMPORTING

  • RETURN_CODE =

TABLES

month_names = month_names

EXCEPTIONS

month_names_not_found = 1

OTHERS = 2

.

READ TABLE month_names INDEX m.

IF sy-subrc = 0.

mname = month_names-ktx.

ENDIF.

concatenate d+6(2) '-' mname '-' d(4) into mname.

ENDFORM. "getmonth

regards,

amit m.

Former Member
0 Kudos

use table t247 with elect logic...

parameters: date like sy-datum.

data: begin of itab occurs 0,

SPRAS type SPRAS,

MNR LIKE T247-MNR,

KTX LIKE T247-KTX,

LTX LIKE T247-LTX,

end of itab.

DATA : month LIKE T247-MNR.

DATA: YEAR(4).

DATA: FINAL(10).

DATA: DAY(2).

DAY = DATE+6(2).

MONTH = DATE+4(2).

YEAR = DATE+0(4).

select SINGLE * from t247 into itab where mnr = month

AND SPRAS = 'E'.

APPEND ITAB.

CONCATENATE DAY ITAB-KTX YEAR INTO FINAL SEPARATED BY '-'.

WRITE: FINAL.