‎2009 Feb 10 12:44 PM
I know there are many post on date calcutation questions but i could not find any answers to my question.
I use following code
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = 20080430
days = 0
months = 1
signum = '-'
years = 0
IMPORTING
calc_date = w_interval-low.
When i substract 2 month from 20080430 i will get w_interval-low 20080330 but 30 april is the last day of the month and therefore i want to have w_interval-low to be filled with 20080331 (last day of march).
Any solutions?
‎2009 Feb 10 12:52 PM
Hi,
SG_PS_GET_LAST_DAY_OF_MONTH
this Function module gives the last day of the month
just subtract one month from the entered date and then pass it to this fm
if it is 01 then make it to 12 and change the year also.
Regards,
Venkatesh
‎2009 Feb 10 12:47 PM
hi,
data: w_date type d value '20080430'.
w_date+6(2) = '01'. " Value in w_date will be '20080401'
subtract 1 from w_date. " w_date = '20080331'
The above code serves your purpose.
This way you can get the last date of the previous month with respect to the given date.
Thanks
Sharath
‎2009 Feb 10 12:52 PM
Hi,
SG_PS_GET_LAST_DAY_OF_MONTH
this Function module gives the last day of the month
just subtract one month from the entered date and then pass it to this fm
if it is 01 then make it to 12 and change the year also.
Regards,
Venkatesh
‎2009 Feb 10 12:54 PM
Hey,
try this FM which suits exactly to your requirement
OIL_LAST_DAY_OF_PREVIOUS_MONTH
regards,
Venkatesh
‎2009 Feb 10 12:54 PM
Hi,
use this Fm to get the last day of the month
LAST_DAY_OF_MONTHS
‎2009 Feb 10 12:55 PM
Hi,
An option is to use function module LAST_DAY_OF_MONTHS. This will return the last day of the month.
As example:
data: l_date type sy-datum,
l_date_result type sy-datum,
l_date_tmp type sy-datum.
l_date = '20080430'.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = l_date
days = 0
months = 1
signum = '-'
years = 0
IMPORTING
calc_date = l_date_result.
call function 'LAST_DAY_OF_MONTHS'
exporting
day_in = l_date
importing
last_day_of_month = l_date_tmp.
if l_date = l_date_tmp.
call function 'LAST_DAY_OF_MONTHS'
exporting
day_in = l_date_result
importing
last_day_of_month = l_date_result.
endif.
This code will just set the resulting date to the end of the month when the initial date as the same - a end of the month.
BR,
Valentin
‎2009 Feb 10 1:01 PM
Hi,
Use this FM: 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
Just copy this code it will give the exact last day of previous month
I tried in my system..it is working..
PARAMETERS : date1 LIKE sy-datum.
CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
EXPORTING
i_date_old = date1
IMPORTING
e_date_new = date1.
.
DATA date2 LIKE sy-datum.
date2 = date1 .
WRITE date2.
Edited by: Kiran Saka on Feb 10, 2009 2:03 PM
‎2009 Feb 10 1:02 PM
This still is not satisfying;
Substract 1 month from date
30042009 - 1 month wil be 30032008, this will mean that my programm which will run on a daily bais will never trigger the date 31032008.
I think i have to substract a certain amount of days to trigger each date in the past.
Edited by: Richard van Veen on Feb 10, 2009 2:02 PM
Edited by: Richard van Veen on Feb 10, 2009 2:03 PM
Edited by: Richard van Veen on Feb 10, 2009 2:03 PM
‎2009 Feb 10 1:20 PM
Use FM
HR_99S_DATE_ADD_SUB_DURATION
this will solve ur query
Regards,
Prasant
‎2009 Feb 10 1:14 PM
‎2009 Feb 10 1:16 PM
Hi Richard,
Instead of using function modules ( as it uses lots of memory since the whole of function group is downloaded you can perform the following code in subroutine and call the subroutine the place you are calling the function-module )
form date_sub using w_date type d
w_month(2) type n.
data :
lw_date like sy-datum.
lw_date = w_date.
lw_date+6(2) = 15.
do w_month times.
subtract 30 from lw_date.
enddo.
w_date0(6) = lw_date0(6). " this will give the changed year and the month
add 1 to lw_date.
if lw_date = '00010102'.
lw_date+6(2) = 28.
do 3 times.
add 1 to lw_date.
if lw_date = '00010102'.
lw_date+6(2) = 28 + sy-index - 1.
exit.
endif.
enddo.
w_date6(2) = lw_date6(2)
endif.
Hope it helps you in saving the performance of your program...
Regards,
Siddarth
‎2009 Feb 10 1:18 PM
Using substraction of 60 days now instead of substracting 2 months!