Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add months to a date?

Tags:

date

abap

I have been given an assignment like this:

I will have a selection screen input box where user enters date and an other input box where he enters number of months.

I have to do is add the given number of months to date and get the new date.

Example: If entered date is 2/3/2011 and given number of months are 5 i should get 7/3/2011.

I know that system date variable 'SY-DATUM' has application server date. And to do date manipulation i can say SY-DATUM + 2.i can only add days,how should i add months.

Please give me a head start.Thanks.

like image 991
Abap newbie Avatar asked Dec 27 '22 10:12

Abap newbie


1 Answers

An easy way to add a number of months to a date is to use the MONTH_PLUS_DETERMINE function module.

Use something like:

data: mydate type sy-datum.
mydate = sy-datum.

call function 'MONTH_PLUS_DETERMINE'
 exporting
  MONTHS  = 5
  OLDDATE = mydate
 importing
  NEWDATE = mydate.

(MONTHS can be negative if you want to subtract.)

There are a lot of other helper functions for date and time calculations. Useful ABAP Function Modules on the SDN Wiki is a good place to go when you're looking for things like that.

like image 63
Mat Avatar answered Feb 15 '23 15:02

Mat