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

Date conversion

Former Member
0 Likes
890

Hi,

I am using a field from the database that holds date in the format YYYYMMDD.

Now i need to compare this field with another field that the user populates which can be in any form DD.MM.YYYY(mostly) or MM.DD.YYYY.

Is anybody aware of a function module that can do the same convert from DD.MM.YYYY to YYYYMMDD.

Thanks & Regards,

Vanita.

7 REPLIES 7
Read only

Former Member
0 Likes
865

try using convert_date_to_internal.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
865

Try this. I believe that this function module works from the user defaults, meaning that it will except the date as it is formatted by the user defaults. In my system, my default is MM/DD/YYYY, so it will convert it to YYYYMMDD. If I send another format like DD/MM/YYYY it doesn't work. I really think that you need to validate the entry of your date so that it is in the correct format.



REPORT ZRICH_0002 .


data: date(10) type c value '12/31/2005'.
data: new_date type sy-datum.


call function 'CONVERT_DATE_TO_INTERNAL'
  exporting
    date_external                  = date
 IMPORTING
   DATE_INTERNAL                  = new_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:/ new_date.

Regards,

Rich Heilman

Read only

christian_wohlfahrt
Active Contributor
0 Likes
865

Hi Vanita!

Usually you define input fields also as type of date (e.g. like sy-datum). Then conversion is done automatically (and you have F4-calendar).

Otherwise you can give FM CONVERSION_EXIT_DATEX_INPUT a try ( or directly DATE_STRING_CONVERT).

Regards,

Christian

Read only

Former Member
0 Likes
865

alternatively you can convert the internal date format into external date format also.

Use

write date_internal to date_external.

where date_internal is type sy-datum and date_external is type char10.

Then you can use the date_external for comparision purposes.

Regards,

Ravi

Read only

Former Member
0 Likes
865

Use this FM <b>convert_date_to_internal.</b>

Read only

Former Member
0 Likes
865

Hi,

Try with RP_FORMATING_DATE

Thanks

Eswar

Read only

Former Member
0 Likes
865

Hi,

Here is the link where u can get all the function modules

of conversions.

http://www.geocities.com/victorav15/sapr3/abapfun.html#date

Regards,

Sharath