Leap year
Can any one help .....
according to the requirement Currently I am adding 1095 days to system date, but in between there will be a leap year , so I need to check wether leap year exsists or not ? Can you tell me how to check ? as this looks simple but I am new to technical and If better give me the code ,
Currently the code is like below :
DATA: P_DATE LIKE SY-DATUM,
P_DATE1 LIKE SY-DATUM.
P_DATE1 = P_DATE + 1095.
Thanks
Rajiv
If you just want to add 3 years (there can either be one leap year or no leap year):
P_DATE1 = P_DATE + 1095.
IF P_DATE1+4(4) NE P_DATE+4(4).
ADD 1 TO P_DATE1.
ENDIF.
P_DATE1 = P_DATE + 1095
Surely SAP will automatically take leap years into consideration when calculating p_date1
_________________
Champions League, here we come...
Thank you very much for quick reply , Can you tell me this logic works for both leap year & normal year as well?
If you just want to add 3 years (there can either be one leap year or no leap year):
P_DATE1 = P_DATE + 1095.
IF P_DATE1+4(4) NE P_DATE+4(4).
ADD 1 TO P_DATE1.
ENDIF.
Keep it simple: P_DATE1 = P_DATE + 1095
Surely SAP will automatically take leap years into consideration when calculating p_date1
Hello friend, I have cross checked the statement what you have said. and it does not happen automatically. if you add 3 to the date(4) , the year gets updated and not the date. You verify yourself to confirm yourself......
thank you,
regards,
Subhas.
P_DATE1 = P_DATE + 1095
Surely SAP will automatically take leap years into consideration when calculating p_date1
Hello friend, I have cross checked the statement what you have said. and it does not happen automatically. if you add 3 to the date(4) , the year gets updated and not the date. You verify yourself to confirm yourself......
thank you,
regards,
Subhas.
Rajiv never said he/she wanted to add 3 years, he/she said 1095 days !
_________________
Champions League, here we come...
there are many checks, remember Y2k?
ok heres a simple onem not the most elegant but u get my point
its about 3 years...
take each of these years in a do loop or whatever , maybe FM it...
your variable is w_date type datum value 31.03.2004
subtract 1 from this into another date field variable?
is the result the 28th or the 29th
there is also the divide by 4/400 rule..
take ur pick
COUPY
I don't think HL's suggestion will work - I think you could end up with a month 15 using that.... it's worth checking (not at my system right now to verify it) but I would consider the previous suggestion to be more worthy.
No, but you could enfd up with an invalid date, say if the start date is 20000229.
Thank you very much for quick reply , Can you tell me this logic works for both leap year & normal year as well?
If you just want to add 3 years (there can either be one leap year or no leap year):
P_DATE1 = P_DATE + 1095.
IF P_DATE1+4(4) NE P_DATE+4(4).
ADD 1 TO P_DATE1.
ENDIF.
As long as you always want to add 3 years, this will work.
If you want to add 6 years, there yould be either one or 2 leap years in the interval, so you would have to do some adjustment, e.g.
p_date1 = p_date + 6571. " ( 6 * 365 + 1)
IF P_DATE1+4(4) NE P_DATE+4(4).
ADD 1 TO P_DATE1.
ENDIF.