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

months

Former Member
0 Likes
1,320

how to find the months inteval between 2 given dates

example 25/11/2007 to 15/08/2007

this is specific to the month interval

11 REPLIES 11
Read only

former_member189059
Active Contributor
0 Likes
1,286

Hello,

Use this FM - <b>HR_PT_COMPUTE_MONTHS</b>

set the modify_interval parameter to P, + or -

Read only

Former Member
0 Likes
1,286

Hi,

Use F.M. HR_HK_DIFF_BT_2_DATES and put Output format as '04'.

Date 1 is the higher date and Date2 is Lower date.

Thanks,

Lalit

Read only

Former Member
0 Likes
1,286

Hi Samuel,

Use HR_99S_INTERVAL_BETWEEN_DATES function module.

<b>Award Points if Useful</b>

Read only

Former Member
0 Likes
1,286

hi samual,

just go through this code.

actually i got the same doubt before and so when i was going through the forum i got these codes and some function modules.

which are given below.

codes.

REPORT YRT_TEST1.

parameters : date1 like sy-datum,

date2 like sy-datum.

data: days(3) type n.

data: years(10) type p decimals 3.

start-of-selection.

days = date2 - date1.

years = days / 365.

REPORT ZDATEDIFF.

DATA: EDAYS LIKE VTBBEWE-ATAGE,

EMONTHS LIKE VTBBEWE-ATAGE,

EYEARS LIKE VTBBEWE-ATAGE.

PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,

TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.

call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

exporting

i_date_from = FROMDATE

i_date_to = TODATE

  • I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS

E_YEARS = EYEARS.

WRITE:/ 'Difference in Days ', EDAYS.

WRITE:/ 'Difference in Months ', EMONTHS.

WRITE:/ 'Difference in Years ', EYEARS.

INITIALIZATION.

FROMDATE = SY-DATUM - 60.

write: / days,

years.

-


Function Modules.

EHS_CALC_YEARS_BETWEEN_DATES

DAYS_BETWEEN_TWO_DATES

MONTHS_BETWEEN_TWO_DATES

HR_99S_INTERVAL_BETWEEN_DATES(Months, Years and days)

COMPUTE_YEARS_BETWEEN_DATES

CSCP_PARA1_GET_PERIODS

Read only

Former Member
0 Likes
1,286

Hi,

follow the below code.

data:

l_diff(3) type n,

l_date1 like sy-datum,

l_date2 like sy-datum.

l_date1 = sy-datum.

l_date2 = sy-datum + 100.

CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'

EXPORTING

i_datum_bis = l_date1

i_datum_von = l_date2

  • I_KZ_INCL_BIS = ' '

IMPORTING

E_MONATE = l_diff.

write:/ l_diff.

reward if useful.

Thanks,

Sreeram.

Read only

Former Member
0 Likes
1,286

use <b>'FIMA_DAYS_AND_MONTHS_AND_YEARS'</b>

for diff in days months and years

all in one.

in ur case ..

REPORT ZDATEDIFF.

DATA: EDAYS LIKE VTBBEWE-ATAGE,

EMONTHS LIKE VTBBEWE-ATAGE,

EYEARS LIKE VTBBEWE-ATAGE.

PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,

TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.

call function <b>'FIMA_DAYS_AND_MONTHS_AND_YEARS'</b>

exporting

i_date_from = FROMDATE

i_date_to = TODATE

  • I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS

E_YEARS = EYEARS.

*WRITE:/ 'Difference in Days ', EDAYS.

WRITE:/ 'Difference in Months ', EMONTHS.

*WRITE:/ 'Difference in Years ', EYEARS.

INITIALIZATION.

FROMDATE = SY-DATUM - 60.

Read only

Former Member
0 Likes
1,286

Hi

Check this

CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES_NEW'

EXPORTING

i_datum_bis = so_pdatu-low

i_datum_von = so_pdatu-high

IMPORTING

E_MONATE = g_f_count_month

Hope it helps.

Praveen

Read only

Former Member
0 Likes
1,286

Hello,

Use Following FM, It will give you Month, Day, years:

CALL FUNCTION 'HRCM_TIME_PERIOD_CALCULATE'

EXPORTING

BEGDA = doj

ENDDA = sy-datum

IMPORTING

NOYRS = cyr

NOMNS = cmn

  • NODYS =

  • EXCEPTIONS

  • INVALID_DATES = 1

  • OVERFLOW = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

Read only

Former Member
0 Likes
1,286

Hi samuel,

You can use FM 'MONTHS_BETWEEN_TWO_DATES' or else

Use offset method like,

date1 = date1+2(2).

date2 = date2+2(2).

Read only

Former Member
0 Likes
1,286

try with following function module:

HR_AUPBS_MONTH_DAY.

i hope it will help you.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,286

Just check this logic and reward if usefull.

DATA : wk_date1 LIKE sy-datum VALUE '20070717', "End date

wk_date2 LIKE sy-datum VALUE '19951201', "Start date

wk_day1(2) TYPE c,

wk_day2(2) TYPE c,

wk_day3(2) TYPE c,

wk_month1(2) TYPE c,

wk_month2(2) TYPE c,

wk_month3(2) TYPE c,

wk_year1(4) TYPE c,

wk_year2(4) TYPE c,

wk_year3(4) TYPE c.

wk_year1 = wk_date1(4).

wk_year2 = wk_date2(4).

wk_month1 = wk_date1+4(2).

wk_month2 = wk_date2+4(2).

wk_day1 = wk_date1+6(2).

wk_day2 = wk_date2+6(2).

wk_day3 = wk_day1 - wk_day2.

wk_month3 = wk_month1 - wk_month2.

wk_year3 = wk_year1 - wk_year2.

*****Month and year calculation

IF wk_month3 < 0.

wk_year3 = wk_year3 - 1.

wk_month3 = 12 + wk_month3.

ELSEIF wk_month3 = 0 AND wk_day3 < 0.

wk_year3 = wk_year3 - 1.

ENDIF.

********Day calculation.

if wk_day3 < 0.

data: last_month_last_day type sy-datum.

last_month_last_day = wk_date1.

last_month_last_day+6(2) = '01'.

last_month_last_day = last_month_last_day - 1.

clear wk_day1.

wk_day1 = last_month_last_day+6(2).

wk_day3 = wk_day3 + wk_day1.

endif.

WRITE : 'Days : ', wk_day3,

/ 'Months : ', wk_month3,

/ 'Years : ', wk_year3.