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

Adding months to date

Former Member
0 Likes
2,117

I need to add 6 months to current date. Also, may be days or years also. Can anyone let me know is there any function module which can be used to achieve the functionality.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,289

Use the below function module...

data : wa_date type sy-datum.

call function 'RP_CALC_DATE_IN_INTERVAL'

exporting

date = sy-datum

days = 0

months = 6

years = 0

signum = '+'

importing

calc_date = wa_date.

Pl. award points if useful.

5 REPLIES 5
Read only

Former Member
0 Likes
1,290

Use the below function module...

data : wa_date type sy-datum.

call function 'RP_CALC_DATE_IN_INTERVAL'

exporting

date = sy-datum

days = 0

months = 6

years = 0

signum = '+'

importing

calc_date = wa_date.

Pl. award points if useful.

Read only

vinod_gunaware2
Active Contributor
0 Likes
1,289

<b>MONTH_PLUS_DETERMINE</b> Add or subtract months from a date. To subtract a month, enter a negative value for the 'months' parameter.

Example:

data: new_date type d.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = -5 " Negative to subtract from old date, positive to add

olddate = sy-datum

IMPORTING

NEWDATE = new_date.

write: / new_date.

<b>RP_CALC_DATE_IN_INTERVAL</b> Add/subtract years/months/days from a date

<b>DATE_IN_FUTURE</b> Import: date in current external format for user; number of days.

Export: calculated date in future in external format mm/dd/yyyy

<b>RE_ADD_MONTH_TO_DATE</b> This module really can add/subtract months to/from date.

regards

vinod

Read only

Former Member
0 Likes
1,289

Hi,

Use FM MONTH_PLUS_DETERMINE.

Regards,

Shashank

Read only

0 Likes
1,289

Hi ,

I can not see MONTH_PLUS_DETERMINE fm in my system unfortunatly .

Can you please send me source code of this .

Waiting for u r response

Thanks

Jimmy

Read only

0 Likes
1,289

Hi jimmy,

here is the code for FM "MONTH_PLUS_DETERMINE".

========================================================

FUNCTION MONTH_PLUS_DETERMINE.

*"----


*"Lokale Schnittstelle:

*" IMPORTING

*" MONTHS

*" OLDDATE LIKE SY-DATUM

*" EXPORTING

*" NEWDATE LIKE SY-DATUM

*"----


DATA: BEGIN OF DAT,

JJJJ(4) ,

MM(2) ,

TT(2) ,

END OF DAT,

BEGIN OF HDAT,

JJJJ(4) ,

MM(2) ,

TT(2) ,

END OF HDAT,

NEWMM TYPE P,

DIFFJJJJ TYPE P.

WRITE: OLDDATE+0(4) TO DAT-JJJJ,

OLDDATE+4(2) TO DAT-MM,

OLDDATE+6(2) TO DAT-TT.

DIFFJJJJ = ( DAT-MM + MONTHS - 1 ) DIV 12.

NEWMM = ( DAT-MM + MONTHS - 1 ) MOD 12 + 1.

DAT-JJJJ = DAT-JJJJ + DIFFJJJJ.

IF NEWMM < 10.

WRITE '0' TO DAT-MM+0(1).

WRITE NEWMM TO DAT-MM+1(1).

ELSE.

WRITE NEWMM TO DAT-MM.

ENDIF.

IF DAT-TT > '28'.

HDAT-TT = '01'.

NEWMM = ( DAT-MM ) MOD 12 + 1.

HDAT-JJJJ = DAT-JJJJ + ( ( DAT-MM ) DIV 12 ).

IF NEWMM < 10.

WRITE '0' TO HDAT-MM+0(1).

WRITE NEWMM TO HDAT-MM+1(1).

ELSE.

WRITE NEWMM TO HDAT-MM.

ENDIF.

IF DAT-TT = '31'.

NEWDATE = HDAT.

NEWDATE = NEWDATE - 1.

ELSE.

IF DAT-MM = '02'.

NEWDATE = HDAT.

NEWDATE = NEWDATE - 1.

ELSE.

NEWDATE = DAT.

ENDIF.

ENDIF.

ELSE.

NEWDATE = DAT.

ENDIF.

ENDFUNCTION.

=========================================================