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

Former Member
0 Likes
872

Hi all,

i get a date in this Format: 06. Jul 06

I want convert it to 06.07.2006.

Is there any FM to do this.

Thanks for Help

Dieter

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
821

Hi Dieter,

Vijays Program works fine with minor modification.

Consider the code.


REPORT  zztest       .
DATA: text(20) TYPE c,
      date     TYPE sy-datum.


*text = '07.JUL.1994'.

text = '06. Jul 06'.


<b>TRANSLATE text TO UPPER CASE.
TRANSLATE text USING '. '.
CONDENSE  text NO-GAPS.</b>



CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'
  EXPORTING
    input  = text
  IMPORTING
    output = date.

WRITE date USING EDIT MASK '__.__.____'.

Thanks to Vijay Babu Dudla.

Regards,

Arun Sambargi.

Message was edited by: Arun Sambargi

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
821

I don't think that there is a function module to do that kind of conversion. You will probably have toe code for that.

Regards,

Rich Heilman

Read only

0 Likes
821

Please try this code.




report zrich_0002.

data: date_in(20) type c value '04. Jul 06'.
data: date_out(10) type c.
data: datum type sy-datum.
data: isplit type table of string with header line.

split date_in at space into table isplit.

read table isplit index 2.
case isplit.
  when 'Jan'.
    isplit = '01'.
  when 'Feb'.
    isplit = '02'.
  when 'Mar'.
    isplit = '03'.
  when 'Apr'.
    isplit = '04'.
  when 'May'.
    isplit = '05'.
  when 'Jun'.
    isplit = '06'.
  when 'Jul'.
    isplit = '07'.
  when 'Aug'.
    isplit = '08'.
  when 'Sep'.
    isplit = '09'.
  when 'Oct'.
    isplit = '10'.
  when 'Nov'.
    isplit = '11'.
  when 'Dec'.
    isplit = '12'.
endcase.
date_out = isplit.

read table isplit index 1.
concatenate date_out isplit+0(2) into date_out..

read table isplit index 3.
concatenate date_out  isplit into date_out.


call function 'CONVERT_DATE_TO_INTERNAL'
     exporting
          date_external = date_out
     importing
          date_internal = datum.

concatenate datum+6(2)
            datum+4(2)
            datum+0(4)
                  into date_out separated by '.'.

write:/ date_out.

Regards,

Rich Heilman

Read only

0 Likes
821

hi Dieter ,

try that:

REPORT ZFORUM96 .
tables t247.
parameters cdate(20) default '06. Jul 06'.
data date1 like sy-datum.

check cdate ca sy-abcde.

SELECT SINGLE * FROM  t247
       WHERE  spras  = sy-langu
       AND    ktx    = cdate+sy-fdpos(3).

replace cdate+sy-fdpos(3) with t247-mnr into cdate.
translate cdate using '. '.
condense cdate no-gaps.
concatenate '20' cdate into date1.
write date1 using edit mask '__.__.____'.

-> see posting below

Andreas

Message was edited by: Andreas Mann

Read only

0 Likes
821

tht's better i think

REPORT zforum96 .
TABLES t247.
PARAMETERS cdate(20) DEFAULT '06. Jul 06'.
DATA date1 LIKE sy-datum.

CHECK cdate CA sy-abcde.

SELECT SINGLE * FROM  t247
       WHERE  spras  = sy-langu
       AND    ktx    = cdate+sy-fdpos(3).

REPLACE cdate+sy-fdpos(3) WITH t247-mnr INTO cdate.
TRANSLATE cdate USING '. '.
CONDENSE cdate NO-GAPS.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
     EXPORTING
          date_external            = cdate
     IMPORTING
          date_internal            = date1
     EXCEPTIONS
          date_external_is_invalid = 1
          OTHERS                   = 2.

WRITE: / date1.

nice weekend to all

and grace!

Andreas

Read only

Former Member
0 Likes
821

Hi,

There is a FM <b>CONVERSION_EXIT_SDATE_INPUT</b>

to do that..

just check it.

 Import parameters               Value           
                                                 
 INPUT                           01.JAN.1994                                                                                
Export parameters               Value           
                                                 
 OUTPUT                          19940101

REPORT  ZZTEST       .
data: text(20), date type sy-datum.
text = '01.JAN.1994'.
CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'
  EXPORTING
    INPUT         = text
 IMPORTING
   OUTPUT        = date
          .
write date. 

Regards

vijay

Read only

Former Member
0 Likes
821

Hi,

Yes u can do it by using this function module-

HRGPBS_HER_FORMAT_DATE

or u can just set the offset according to this FM and use it!!!

Hope this helps u!!!

Regards,

Seema.

Read only

Former Member
0 Likes
821

hi ,

i guess u can create ur own function module.

if you go to table T247.

you will find a field LTX .so in your function module under source code ,include this code.

***********code****************

under source code in your function module.

if get_number_months NE space.

select ltx MNR from t247

into corresponding fields of table i_month

where MNR = get_number_months and

SPRAS = 'EN'.

endif.

************************************

under import parameters

parameter name type associatedtype short text

get_number_months like t247-ltx month name.

under tables tab.

parameter name type associatedtype short text

i_month like t247 month_details.

Please mark helpful answers

Read only

Former Member
0 Likes
821

Hi

Check out the function module <b>'MONTH_NAMES_GET'.</b>

This might help you.

Cheers,

Anirban.

Message was edited by: ANIRBAN DUTTA

Read only

Former Member
0 Likes
822

Hi Dieter,

Vijays Program works fine with minor modification.

Consider the code.


REPORT  zztest       .
DATA: text(20) TYPE c,
      date     TYPE sy-datum.


*text = '07.JUL.1994'.

text = '06. Jul 06'.


<b>TRANSLATE text TO UPPER CASE.
TRANSLATE text USING '. '.
CONDENSE  text NO-GAPS.</b>



CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'
  EXPORTING
    input  = text
  IMPORTING
    output = date.

WRITE date USING EDIT MASK '__.__.____'.

Thanks to Vijay Babu Dudla.

Regards,

Arun Sambargi.

Message was edited by: Arun Sambargi