Application Development 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: 

Current date + 1 year

former_member1326872
Participant
0 Kudos
4,540

Hi,

Can anyone please tell me what is the easy method to calculate current date + 1 year?

Is there any function module available?

Thanks..

Swetha.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
745

This can work.


DATA:
  work_dt      TYPE d.

START-OF-SELECTION.
  work_dt = sy-datum.
  work_dt(4) = work_dt(4) + 1.

  IF work_dt+4(4) = '0229'.
    work_dt+4(4) = '0228'.
  ENDIF.

  WRITE:/ work_dt.

11 REPLIES 11

Former Member
0 Kudos
745

hi ,

use this..

parameters: p_date type sy-datum.

data:p_out type sy-datum.

p_out = sy-datum + 365.

write:/ p_out.

or use this fm ISM_ADD_YEAR_TO_PERIOD

regards,

venkat.

Edited by: venkat appikonda on Mar 21, 2008 4:06 PM

Former Member
0 Kudos
746

This can work.


DATA:
  work_dt      TYPE d.

START-OF-SELECTION.
  work_dt = sy-datum.
  work_dt(4) = work_dt(4) + 1.

  IF work_dt+4(4) = '0229'.
    work_dt+4(4) = '0228'.
  ENDIF.

  WRITE:/ work_dt.

0 Kudos
745

Beware of Leap Years.

I Tried this and it works


data date type sy-datum.
data i_date type sy-datum value '20080229'.
CALL FUNCTION 'ADD_TIME_TO_DATE'
  EXPORTING
    I_IDATE                     = i_date
    I_TIME                      = '1'
    I_IPRKZ                     = '3'
*   I_RDMHD                     =
 IMPORTING
   O_IDATE                     = date
* EXCEPTIONS
*   INVALID_PERIOD              = 1
*   INVALID_ROUND_UP_RULE       = 2
*   INTERNAL_ERROR              = 3
*   OTHERS                      = 4
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

write date.

i_iprkz = 3 means years and i_time is the increase

0 Kudos
745

Hi Rmairo can u plz eloborate i_uprkz i didnt get that..?

will u please

because leap years how can it judges..?

0 Kudos
745

Leap year is computed by

remainder = mod ( year / 4 ).

if remainder = 0 then leap year is true

EXCEPT when year+0(2) / 4 remainder NE 0. ie.. 2000 was leap year, but 1900 was not.

0 Kudos
745

i_iprkz is the unit you want to increase, you have options days, weeks, months and years.

I said adding 365 days to the date is not the right answer.

For example, if you have 01.01.2008 most people assume that date plus 1 year is 01.01.2009, but if you add 365 days in a leap year like 2008 you end with 31.12.2008.

The function adds 1 year to the date and in case you place 29.02 the function checks the plausability, if you add years that will not have a 29.02, the function places the new date in 28.02 of the years you added, but in case you add any multiples of 4, it will put the date in 29.02 of that year.

The same thing most people born in 29.02 do with their birthdays, must countries have legislastion to place their birthdays in 28.02 in non-leap years an 29.02 in leap years.

0 Kudos
745

OK Ramiro ,

Thanks for taking efforts to answer my question on behalf of miss swetha.

so i am going to fix this...

CALL FUNCTION 'ADD_TIME_TO_DATE'

EXPORTING

I_IDATE = i_date

I_TIME = '1' --> only accepts how many years

I_IPRKZ = '3' --> specified for only leap years?

*I_RDMHD =

will u agree with my comments mentioned..?

Actually i mean can we use this same function module for weeks or days like 4 weeks later what is the date or after 5 months what is the date ?

If so how?

Edited by: saslove sap on Mar 21, 2008 6:13 PM

0 Kudos
745

No. Maybe something like this


CALL FUNCTION 'ADD_TIME_TO_DATE'
  EXPORTING
    I_IDATE                     = i_date "Original date
    I_TIME                      = '1'  " Ammount to add
    I_IPRKZ                     = '3'  " unit: 'blank'-days 1-weeks 2-months 3-years
*   I_RDMHD                     =
 IMPORTING
   O_IDATE                     = date "new date
* EXCEPTIONS
*   INVALID_PERIOD              = 1
*   INVALID_ROUND_UP_RULE       = 2
*   INTERNAL_ERROR              = 3
*   OTHERS                      = 4.

Yes, you can use the same function to add days, weeks or months also

Edited by: Ramiro Escamilla on Mar 21, 2008 6:18 PM

0 Kudos
745

ya thanks ....

sorry to ditrub i just gone to the data elements structure of mara i found it out..

hi swetha kindly provide full marks to ramiro.....

really thanks once again

sas

0 Kudos
745

Thanks a lot..

Former Member
0 Kudos
745

sy-datum+365 works well