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 string to date

Former Member
0 Likes
4,530

hi all,

i have the following requirement

in a function module i have import parameter of type string

theres an table with one of its field to be of type dats

in the function module i am getin the from d db those records that have this date value by comparing my import param with the db value.

how do i compare char and date...is there any conversion in either way.

Regards

Jayapriya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,624

hi

have a look onthis code...Its helpfull only if the string's first 2 place holds date ,next two place has month and other four has year ...

REPORT ZDATEDIFF .

data :var3 type sy-datum.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = '11092008'

IMPORTING

date_internal = var3

EXCEPTIONS

date_external_is_invalid = 1

OTHERS = 2.

write var3.

if you wanna convert the string like bellow

lv_date = '2006-12-07' then use this code .

DATA : lv_date(15) type C ,L_VAR2 like sy-datum.

lv_date = '2006-12-07'.

CONCATENATE lv_date8(2) '.' lv_date5(2) '.' lv_date(4) INTO lv_date.

write lv_date.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

DATE_EXTERNAL = lv_date

IMPORTING

DATE_INTERNAL = L_VAR2

EXCEPTIONS

DATE_EXTERNAL_IS_INVALID = 1

OTHERS = 2.

write : L_VAR2.

hope the content is usefull

regards

R@SAP.

Edited by: R@SAP on Jan 22, 2009 1:22 PM

6 REPLIES 6
Read only

former_member156446
Active Contributor
0 Likes
1,624

frequent question type

Search before post

Read only

Former Member
0 Likes
1,624

hi.

character formats can always be compared,u insert the date field to character field and compare.

Edited by: soniya baboo on Jan 22, 2009 1:07 PM

Read only

Former Member
0 Likes
1,625

hi

have a look onthis code...Its helpfull only if the string's first 2 place holds date ,next two place has month and other four has year ...

REPORT ZDATEDIFF .

data :var3 type sy-datum.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = '11092008'

IMPORTING

date_internal = var3

EXCEPTIONS

date_external_is_invalid = 1

OTHERS = 2.

write var3.

if you wanna convert the string like bellow

lv_date = '2006-12-07' then use this code .

DATA : lv_date(15) type C ,L_VAR2 like sy-datum.

lv_date = '2006-12-07'.

CONCATENATE lv_date8(2) '.' lv_date5(2) '.' lv_date(4) INTO lv_date.

write lv_date.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

DATE_EXTERNAL = lv_date

IMPORTING

DATE_INTERNAL = L_VAR2

EXCEPTIONS

DATE_EXTERNAL_IS_INVALID = 1

OTHERS = 2.

write : L_VAR2.

hope the content is usefull

regards

R@SAP.

Edited by: R@SAP on Jan 22, 2009 1:22 PM

Read only

Former Member
0 Likes
1,624

Take the Local Variable of Date Type and You can send the Value into that variable

Read only

Former Member
0 Likes
1,624

Hi,

Check the below thread

Regards,

Anki Reddy

Read only

0 Likes
1,624

That's a way to do it in Java, not ABAP.