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

what function module will compare 2 dates?

Former Member
0 Likes
6,773

what function module will specify which date is greater and which date is lesser when we have 2 dates.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,159

hi leela,

no need to use Function Module for this small issue because if you use it will take much time to run.Better you compare like

data: date1 type sy-datum,

date2 type sy-datum.

if date1 gt date2

MESSAGE 'Date1 is greater.' type 'I'.

else

MESSAGE 'Date2 is greater.' type 'I'.

or otherwise you can use

'FIMA_DAYS_AND_MONTHS_AND_YEARS' OR

'DAYS_BETWEEN_TWO_DATES' OR

REWARDS IF USEFUL

9 REPLIES 9
Read only

former_member188829
Active Contributor
0 Likes
2,159

data:x1 like sy-datum.

data:x2 like sy-datum.

if x2 > x1.

write:/ x2 , 'is high'.

else.

write:/ x1 , 'is High'.

endif.

Message was edited by:

Vishnu Reddy

Message was edited by:

Vishnu Reddy

Read only

Former Member
0 Likes
2,159

Hi,

I don't think you need FM for this.

Try this...


DATA : date1 LIKE sy-datum,
            date2 LIKE sy-datum.

IF date1 GT date2.
------" do something
ELSE.
------
ENDIF.

Read only

Former Member
0 Likes
2,159

DATA V_DIFF TYPE I.

PARAMETERS P_BIRTHD LIKE SY-DATUM.

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

EXPORTING

I_DATUM_BIS = SY-DATUM

I_DATUM_VON = P_BIRTHD

IMPORTING

E_TAGE = V_DIFF

EXCEPTIONS

DAYS_METHOD_NOT_DEFINED = 1

OTHERS = 2.

IF SY-SUBRC EQ 0.

WRITE:/ V_DIFF, 'DAYS HAVE PASSED SINCE', P_BIRTHD.

ELSE.

WRITE:/ 'ERROR IN CALCULATION'.

ENDIF.

Read only

Former Member
0 Likes
2,159

hi,

u need not go for a FM, u can just subtract the dates and find which s higher

Read only

Former Member
0 Likes
2,159

Hi,

SD_DATETIME_DIFFERENCE it gives the difference in Days and Time for 2 dates

Reward if helpful

Read only

Former Member
0 Likes
2,159

Hi,

You don't need any function to compare date, SAP do that without any function.

date_1 - date_2 will give you number of day between date_1 and date_2 ....

You need function if you want to work of factory calendar.

You can compare these using the function module DURATION_DETERMINE. This fuction will give you the difference, and it can be in a view different units, such as the difference in days, months, etc.

Regards,

Omkar.

Message was edited by:

Omkaram Yanamala

Read only

Former Member
0 Likes
2,159

hi leela,

you can use the following function module :

SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2 dates.

reward points if helpful..

Read only

Former Member
0 Likes
2,159

Hi,

You can do as below :

parameter : date1 like sy-datum,
            date2 like sy-datum.

INITIALIZATION.

date1 = '20070130'.
date2 = '20070225'.

START-OF-SELECTION.

if date1 GT date2.
  write : 'date1 is greater'.

else.
    write : 'date2 is greater'.
endif.

Thanks,

Sri.

Read only

Former Member
0 Likes
2,160

hi leela,

no need to use Function Module for this small issue because if you use it will take much time to run.Better you compare like

data: date1 type sy-datum,

date2 type sy-datum.

if date1 gt date2

MESSAGE 'Date1 is greater.' type 'I'.

else

MESSAGE 'Date2 is greater.' type 'I'.

or otherwise you can use

'FIMA_DAYS_AND_MONTHS_AND_YEARS' OR

'DAYS_BETWEEN_TWO_DATES' OR

REWARDS IF USEFUL