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

Converting Date Formats

former_member758034
Participant
0 Likes
6,024

Hi all,

I know there are many such posts but i was unable to find an answer that suited my requirement.

I want to convert the internal date format into the format specified below. Is there any FM's for this or do i have to code it?

For Ex:

Internal Format : 20130218

Format Needed : 18th February 2013

I found the FM CONVERSION_EXIT_LDATE_OUTPUT but it does not add the th to the date.

Any Help will be greatly appreciated.

Thanks

1 ACCEPTED SOLUTION
Read only

Bhushan_hs
Participant
0 Likes
5,662

Hi

I don't think any function module would give you the desired result as expected by you.

But you can modify the function module based on your requirement.

20 REPLIES 20
Read only

Former Member
0 Likes
5,662

Hello,

I have a suggestion for you, but is not actually such a good method.

You can try;

DATA: LV_DATUM(15).

CALL FUNCTION 'CONVERSION_EXIT_LDATE_OUTPUT'

   EXPORTING

     INPUT  = P_DATUM

   IMPORTING

     OUTPUT = LV_DATUM.

REPLACE ALL OCCURRENCES OF '.' IN LV_DATUM WITH 'th'.

Read only

0 Likes
5,662

Thats what i thought i would have to do..

Thanks a lot..

Read only

Former Member
0 Likes
5,662

Hi,

I think for your requirement there is no function module available you have to write the code as below

please check the below link

http://scn.sap.com/thread/1112656

Definately it will help u.

Thanks

Mani

Read only

0 Likes
5,662

Thank you Mani..

Read only

Bhushan_hs
Participant
0 Likes
5,663

Hi

I don't think any function module would give you the desired result as expected by you.

But you can modify the function module based on your requirement.

Read only

0 Likes
5,662

Thanks Nagbhushan

Read only

Former Member
0 Likes
5,662

Hi,

Write a simple select query on table T247.

Thanks,

Tooshar Bendale

Read only

0 Likes
5,662

Thanks Tooshar,

But doing that will give me the month in long form, not the whole date.

Thanks

Read only

0 Likes
5,662

Hi use the function module

HR_IN_GET_DATE_COMPONENTS

It will give the day, month and year.

Hope this helps.

Thanks,

Tooshar Bendale

Read only

0 Likes
5,662

The FM has a issue.

Month Day and Year are of type c( 1 char long). Hence when u pass sy-datum to it gives an exception since it cant take the whole of the month number..

Read only

0 Likes
5,662

Hi,

You had entered a wrong date. Check the screen shot attached.

Thanks,

Tooshar Bendale

Read only

0 Likes
5,662

Thanks ,

It does work, but i have to add the th manually..

Thanks

Read only

vinoth_aruldass
Contributor
0 Likes
5,662

hi,

with th will not come in any function module you have to write select query in t247 table and concatenate date 'th' month and year ..

hope it helps,

Vinoth

Read only

former_member758034
Participant
0 Likes
5,662

Thanks everyone..

Guess i will have to add the th manually..

Read only

Former Member
0 Likes
5,662

hi ,   As suggested by Nagabhushan earlier, u can copy the FM and add the code after output statement.

data day1 type c. 

   day1 = output+1(1).

if day1 = 1.

  replace all occurrences of  '.' in output  with 'st'. 

elseif day1 = 2. 

  replace all occurrences of  '.' in output  with 'nd'.   

elseif day1 = 3.       replace all occurrences of  '.' in output  with 'rd'.   

  else. replace all occurrences of  '.' in output  with 'th'.

endif. 

Thanks

  Vijay

Read only

0 Likes
5,662

Hi Rudra,

Its very simple. Just get the year date and month separated.

w_year = w_input+0(4) = 2013

w_date = w_input0+6(2) = 18

w_month = w_input0+4(2) = 02

Internal Format : 20130218

Assign the month name as per the month number we get in the w_month variable.

and the concatenate accordingly  to get the final answer.

Read only

0 Likes
5,662

Thanks

Read only

0 Likes
5,662

Thanks

Read only

0 Likes
5,662

May be this REGEX solution helps which I got from some other post.

FORM regex .
  DATA:
    lt_string TYPE TABLE OF string.
  FIELD-SYMBOLS:
    <string>  TYPE string.
  APPEND:
    '20. SEP 2009' TO lt_string,
    '31. SEP 2009' TO lt_string,
    '22. SEP 2009' TO lt_string,
    '20. SEP 2009' TO lt_string,
    '23. SEP 2009' TO lt_string,
    '02. SEP 2009' TO lt_string,
    '1. SEP 2009' TO lt_string,
    '26. SEP 2009' TO lt_string,
    '5. SEP 2009' TO lt_string.
  LOOP AT lt_string ASSIGNING <string>.
    WRITE: / <string>, 'converts to'.
    DO 1 TIMES.
      REPLACE REGEX '^(\d{0,1}1)\.'   IN <string> WITH `$1st ` .
      CHECK sy-subrc <> 0.
      REPLACE REGEX '^(\d{0,1}2)\.'   IN <string> WITH `$1nd ` .
      CHECK sy-subrc <> 0.
      REPLACE REGEX '^(\d{0,1}3)\.'   IN <string> WITH `$1rd ` .
      CHECK sy-subrc <> 0.
      REPLACE REGEX '^(\d{0,1}[0,4-9])\.'   IN <string> WITH `$1th ` .
    ENDDO.
    WRITE:  <string>.

  ENDLOOP.
ENDFORM.                    " REGEX

creates output


20. SEP 2009 converts to 20th  SEP 2009
31. SEP 2009 converts to 31st  SEP 2009
22. SEP 2009 converts to 22nd  SEP 2009
20. SEP 2009 converts to 20th  SEP 2009
23. SEP 2009 converts to 23rd  SEP 2009
02. SEP 2009 converts to 02nd  SEP 2009
1. SEP 2009 converts to 1st  SEP 2009
26. SEP 2009 converts to 26th  SEP 2009
5. SEP 2009 converts to 5th  SEP 2009

Regex explained:

^(\d{0,1}1)\.

^ - begin of string

d{0,1}1

- zero or one digit followed by "1"

()  - brackets create a back reference to what is inside the brackets

replace with  `$1st `

- use `colon to preserve trailing blanks

$1 - use back reference # 1 (matched substring), contents of first () bracket pair

st - use st as in 1st

Read only

gurunathkumar_dadamu
Active Contributor
0 Likes
5,662

Hi Rudra,

yes,according to Dnyaneshwar follow the code and add this.

case w_month.

when '01'.

lv_name = 'January.

when '02'

lv_name = 'Febraury.

......

endcase.

concatenate w_date lv_name w_year into w_format.

Regards,

Gurunath Kumar D