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

code for difference of dates

Former Member
0 Likes
1,335

hi,

pls give me the code for finding out the difference between the two dates entered in select-options for validations to find whether the difference is less than 12 months or not.

and pls say me why do people say that it is a performance issue to have the difference more than a year

thanks and i will offer ten points for the answer,

thanking you,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,212

Hi

12 months have 365 days, so you can write:

PATAMETERS: DAY_1 LIKE SY-DATUM,
                        DAY_2 LIKE SY-DATUM.
DATA DELTA TYPE I.

AT SELECTION-SCREEN.

DELTA = DAY_2 - DAY_1.

IF DELTA > 365.
  MESSAGE ERROR
ENDIF.

Max

11 REPLIES 11
Read only

Former Member
0 Likes
1,212

Hi

Use FM HR_HK_DIFF_BT_2_DATES

Thanks

Sandeep

Reward if helpful

Read only

0 Likes
1,212

hello sandeep,

thanks for your kind reply

when i am using that function module like

keeping the importing days as

v_days type p

i am getting the type conflict error

please suggest me to keep exact types for using the fm

thanks in advance and will surely reward ten points if you give me the exact answer

Read only

Former Member
0 Likes
1,213

Hi

12 months have 365 days, so you can write:

PATAMETERS: DAY_1 LIKE SY-DATUM,
                        DAY_2 LIKE SY-DATUM.
DATA DELTA TYPE I.

AT SELECTION-SCREEN.

DELTA = DAY_2 - DAY_1.

IF DELTA > 365.
  MESSAGE ERROR
ENDIF.

Max

Read only

Former Member
0 Likes
1,212

Hi..

u want to get the diff of dates between the high and low values of a select-options .right?? thenu can simply say

diff = s_opt-high - s_opt-low where s_opt is the select-options of ur date .

i hope i am clear.if not let me know.

Regards,

kamal

Read only

Former Member
0 Likes
1,212

DAYS_BETWEEN_TWO_DATES

MONTHS_BETWEEN_TWO_DATES Integer number

MONTHS_BETWEEN_TWO_DATES_NEW

Most universal FM to determine months (both integer and float values)

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

EXPORTING

I_DATUM_BIS = x_faede-zfbdt

I_DATUM_VON = p_fdat

I_KZ_EXCL_VON = '0'

I_KZ_INCL_BIS = '0'

I_KZ_ULT_BIS = ' '

I_KZ_ULT_VON = ' '

I_STGMETH = '0'

I_SZBMETH = '1'

IMPORTING

E_TAGE = dias_v.

IF SY-SUBRC <> 0.

ENDIF.

donde:

x_faede-zfbdt -> 20050915

p_fdat -> 20050811

dias_v = 4

Read only

Former Member
0 Likes
1,212

hi,

use the fun mod - RELATIVE_DATE_CALCULATE -- to find date after some duration

fun mod - <b> /SDF/CMO_DATETIME_DIFFERENCE -- for diff</b>

With Regards,

S.Barani

Read only

anversha_s
Active Contributor
0 Likes
1,212

hi,

You can use aqny of these FM.

MONTHS_BETWEEN_TWO_DATES
MONTHS_BETWEEN_TWO_DATES_NEW

HR_99S_MONTHS_BETWEEN_DATES

HR_MONTHS_BETWEEN_TWO_DATES

and chk the diff in months is greater than 12 or not.

Regards

Anversha

Read only

former_member196280
Active Contributor
0 Likes
1,212

Use FM <b>'DAYS_BETWEEN_TWO_DATES'</b>

Regards,

SaiRam

Read only

abhishek_shukla3
Explorer
0 Likes
1,212

Use FM :

SD_DATETIME_DIFFERENCE

Read only

Former Member
0 Likes
1,212

Try these FMs,

1. HR_SGPBS_YRS_MTHS_DAYS

2. HR_SEN_CALE_DAYS_DURATION

Read only

Former Member
0 Likes
1,212

hi sara,

as coding u can write as

data: date1 like sy-datum,

date2 like sy-datum

result(10) like type c.

if date2 - date1 >= 365.

write: /10 'hai'.

else.

write e000(zmessclas) with 'date range should be 365 days r 12 months'.

endif.

if helpful reward some points.

with regrads,

suresh babu aluri.