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

CONVERT DATE RANGE INTO MONTHS

Former Member
0 Likes
3,050

HI FRIENDS,

ACTUALLY IN MY SELECT-OPTIONS I HAVE USED DATE BETWEEN 03/06/1980 TO 04/12/1980

BASED ON THIS DATE I HAVE TO CALCULATE NUMBER OF MONTHS.

WILL THIS BE DONE AUTOMATICALLY OR I NEED TO WRITE ANY CODE FOR CONVERTING THE DATE RANGE INTO NUMBER OF MONTHS.

REGARDS

SIRI.

1 ACCEPTED SOLUTION
Read only

suresh_datti
Active Contributor
0 Likes
2,133

You can use the function module 'MONTHS_BETWEEN_TWO_DATES' in your program .

~Suresh

10 REPLIES 10
Read only

Laxmana_Appana_
Active Contributor
0 Likes
2,133

Hi,

Use FM's : MONTHS_BETWEEN_TWO_DATES_NEW

MONTHS_BETWEEN_TWO_DATES

FIMA_DAYS_AND_MONTHS_AND_YEARS

Sample code :

DATA : x_no_months type i.
DATA : x_stdat like sy-datum,
       x_enddat like sy-datum.

 
       x_stdat  = s_date-low
       x_enddat = s_date-high

CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
    EXPORTING
      i_datum_bis = x_stdat
      i_datum_von = x_enddat
    IMPORTING
      e_monate    = x_no_months.

x_no_months will contain no.of months.

Regards

Appana

Read only

0 Likes
2,133

tHANX APPANA,

AFTER CONVERTING THAT DATES INTO MONTHS I SHOUILD VALIDATE THAT MONTHS SO AS THAT SHOULD BE ONLY BETWEEN 1 AND 12 ONLY .

CAN U PLZ HELP ME.

REGARDS,

SIRI.

Read only

0 Likes
2,133

Hi,

Check this code :

IF x_months BETWEEN 1 AND 12.
 write ' with in the range'.
ELSE.
write ' out of range'.
ENDIF.

Regards

Appana

Read only

0 Likes
2,133

Hello Sireesha.

It depends on your requirement actually it is not needed but if you have the requirement that the dates have to be within a year ...in that case you need to validate it to be between 1 to 12..otherwise not needed.

pls note that the answer of the FM would be 0 if you the date range is within the same month...i.e. 29.08.2006 and 01.08.2006 would return the answer as ZERO.

Rgds

Anurag

Message was edited by: Anurag Bankley

Read only

0 Likes
2,133

yes ANURAG MY REQUIREMENT IS L TO VALIDATE THE MONTHS SO THEY SHOULD BE ONLY BETWEEN 1 AND 12 .

BECAUSE COUNTING IS FOR ONE YEAR AND COUNTED EVERY MONTH

SO THE DATES I GIVE WILL NOT IN ONE MONTH E.

THANKX.

SIRI.

Read only

suresh_datti
Active Contributor
0 Likes
2,134

You can use the function module 'MONTHS_BETWEEN_TWO_DATES' in your program .

~Suresh

Read only

Former Member
0 Likes
2,133

HR_ECM_GET_PERIOD_BETW_DATES

Read only

Former Member
0 Likes
2,133

Hi

you can check this FM

HR_ECM_GET_NUMBER_OF_MONTHS

It gives the number of months between 2 dates

best regards,

Thangesh

Read only

Former Member
0 Likes
2,133

you can use the below logic.

at selection-screen.

call function 'MONTHS_BETWEEN_TWO_DATES_NEW'

exporting

i_datum_bis = s_date-high

i_datum_von = s_date-low

i_kz_incl_bis = SPACE

i_kz_volle_monate = 'X'

importing

e_monate = lmonths.

Regards

Anurag

Read only

Former Member
0 Likes
2,133

Hi Sireesha,

You can also use following method.

CL_RECA_DATE->MONTHS_BETWEEN_TWO_DATES.

Inputs to this method are:

ID_DATE_TO type sy-datum required

ID_DATE_FROM type sy-datum required

output is:

RD_MONTHS : No. of months between entered dates.

Hope this helps.

Regards.

vishwas.