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 to internal format

Former Member
0 Likes
50,693

Hi,

I am getting date in the format as detailed below:

10/16/2005, 6/16/2005, 10/6/2005 - MM/DD/YYYY

I have to convert it to the internal date format.

Please help with the code.

Thanks

SAPBW

1 ACCEPTED SOLUTION
Read only

Former Member
16,858

Hi,

Use the function module CONVERT_DATE_TO_INTERNAL..

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

DATE_EXTERNAL = V_DATE_EX

IMPORTING

DATE_INTERNAL = V_DATE.

Thanks,

Naren

5 REPLIES 5
Read only

Former Member
16,859

Hi,

Use the function module CONVERT_DATE_TO_INTERNAL..

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

DATE_EXTERNAL = V_DATE_EX

IMPORTING

DATE_INTERNAL = V_DATE.

Thanks,

Naren

Read only

Former Member
0 Likes
16,858

HI,

Use Function module <b>CONVERT_DATE_TO_INTERNAL</b>

  CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
      EXPORTING
           DATE_EXTERNAL            =  PL_BUDAT
      IMPORTING
           DATE_INTERNAL            =  P_BUDAT
      EXCEPTIONS
           DATE_EXTERNAL_IS_INVALID = 1
           OTHERS                   = 2.

Regards

Sudheer

Read only

Former Member
0 Likes
16,858

Hi,

Use Function module <b>CONVERT_DATE_TO_INTERNAL</b>.

It will consider all types of date formats 10/16/2005, 6/16/2005, 10/6/2005 etc. Whether you will give 1 or 2 digits to month or date. You can also give 2 digits to year even then it will converts to internal format.

<b>You need to give dates in User defined format otherwise it generates an exception DATE_EXTERNAL_IS_INVALID.</b>

DATA V_EXT_DATE(10) VALUE '10/06/2005'.

DATA V_DATE TYPE SY-DATUM.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = V_EXT_DATE

IMPORTING

DATE_INTERNAL = V_DATE

EXCEPTIONS

DATE_EXTERNAL_IS_INVALID = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE:/ 'INTERNAL FORMAT OF DATE IS: ', V_DATE.

Thanks,

Vinay

Thanks,

Vinay

Read only

Former Member
16,858

Use the FM <b>/SAPDMC/LSM_DATE_CONVERT</b>.

Pass DATE_IN = 10/16/2005

DATE_FORMAT_IN = DMDY

TO_OUTPUT_FORMAT = BLANK

TO_INTERNAL_FORMAT = X

OUTPUT

DATE_OUT = 20051016

Regards,

Prakash.

Read only

PRAGSMATIC
Participant
0 Likes
16,858
cl_abap_datfm=>conv_date_ext_to_int
cl_abap_datfm=>conv_date_ext_to_int(
EXPORTING
im_datext = rv_date " external representation of date
im_datfmdes = iv_pattern " date format provided
IMPORTING
ex_datint = DATA(lv_int_date) " internal representation of date



cl_abap_datfm=>conv_date_int_to_ext
cl_abap_datfm=>conv_date_int_to_ext(
EXPORTING
im_datint = CONV d( rv_date ) " internal representation of date
im_datfmdes = iv_pattern " date format wanted for conversion
IMPORTING
ex_datext = rv_date " external representation of date