Application Development 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: 

converting the date

Former Member
0 Kudos

i need to convert the date from the following formats

1. MM/DD/YYYY

2. MM-DD-YYYY

3. YYYY/MM/DD

4. YYYY-MM-DD

5. DD.MM.YYYY

6. YYYY.MM.DD

to MM.DD.YYYY FORMAT.

THANKS AND REGARDS

PRIYA

6 REPLIES 6

Former Member
0 Kudos

Hi,

imagine 20080908 is sy-datum

data : date(10) type c.

date0(2) = sy-datum4(2). move '09' first

date+2(1) = '.'.

date3(2) = sy-datum6(2). move '08'

date+5(1) = '.'.

date6(4) = sy-datum0(4). move '2008'

Regards,

Neenu

bpawanchand
Active Contributor
0 Kudos

Hi

You can convert any kind of date by using the OFFSET

For example

YYYY/MM/DD

DATA :
    w_d1 TYPE sy-datum VALUE '2008/10/15'.
   w_str  TYPE string.
   w_dot TYPE c VALUE'.'.

 CONCATENATE w_d1+6(2) w_dot w_d1+4(2)  w_dot w_d1+0(4) INTO w_str.

WRITE:
    w_str.

Output will be

15.10.2008

Regards

Pavan

Former Member
0 Kudos

Hi,

Check the code below.

  • For getting date format in the form like 10.Dec.2008

WHEN '01'.

CALL FUNCTION 'CONVERSION_EXIT_SDATE_OUTPUT'

EXPORTING

input = date2

IMPORTING

output = date_format.

IF sy-subrc EQ 0.

date_format1 = date_format.

ENDIF.

  • For getting date in the format like 10.December.2008

WHEN '02'.

CALL FUNCTION 'CONVERSION_EXIT_SDATE_OUTPUT'

EXPORTING

input = date2

IMPORTING

output = date_format.

IF sy-subrc EQ 0.

Get Month Long text

SELECT SINGLE ltx

FROM t247 INTO ws_month

WHERE ktx EQ date_format+3(3)

AND spras EQ 'E'.

IF sy-subrc EQ 0.

CONCATENATE date_format0(2) ws_month date_format7(4) INTO date_format1 SEPARATED BY space.

ENDIF.

ENDIF.

Thanks & Regards,

Naresh

Former Member
0 Kudos

Hi,

Do you need a FM for these?

I think you can do it with code.

1. w_date = MM/DD/YYYY

Code : Replace all occurences of '/' in w_date with '.'.

O/p : MM.DD.YYYY.

2. w_date = MM-DD-YYYY

Code : Replace all occurences of '-' in w_date with '.'.

O/p : MM.DD.YYYY.

3. w_date = YYYY/MM/DD or YYYY-MM-DD or YYYY.MM.DD

Code : Data w_date1(10) type c,

Concatenate w_date6(2) '.' w_date4(2) '.' w_date+0(4) into w_date1.

4. w_date = DD.MM.YYYY

Code : w_inter(2) type c.

w_inter = w_date+0(2).

w_date0(2) = w_date3(2).

w_date+3(2) = w_inter.

Regards,

Pramod

Former Member
0 Kudos

>

> i need to convert the date from the following formats

> 1. MM/DD/YYYY

> 2. MM-DD-YYYY

> 3. YYYY/MM/DD

> 4. YYYY-MM-DD

> 5. DD.MM.YYYY

> 6. YYYY.MM.DD

>

> to MM.DD.YYYY FORMAT.

>

> THANKS AND REGARDS

> PRIYA

I don't know of any standard SAP functions that can handle this kind of date conversion. So, i guess you have to write it yourself.

Personally my approach would be this.

1. check if the date holds which separator.

2. split the date at the separator into an internal table.

3. thus your internal table will always have 3 lines: DD, MM and YYYY

4. loop at the internal table to determine

4a. which line holds the year: the length of the value in that line is always 4.

4b. which line holds the month: month can never exceed the value of 12.

The only problem i see is that 12/04/2008 (4 december 2008) and 12.04.2008 (12 april 2008) are not the same (based on your definition).

Former Member
0 Kudos

Hi ,

Try using the following function module

HR_IN_GET_DATE_COMPONENTS

if you pass date(in any formate) you will get day, month and year.

using 'concatenate' key word get the required formate.

Regards,

Jaya Vani.