5 Replies Latest reply: Feb 14, 2012 7:23 AM by Anoop Francis

# Get the date of last year ?

Currently Being Moderated

Experts,

in my CMOD, we calulate previous year like this...... Date(4) = Date(4) -1.

Til now it works gr8, but now, February 2012 has 29 days, so this logic fails.

So, is there a FM which can calculate Previous year date ?

So, if i input 2012/02/29 and the FM gives me 2011/02/28 ???

thanks

• ###### Re: Get the date of last year ?
Currently Being Moderated

Hi,

http://wiki.sdn.sap.com/wiki/display/ABAP/FunctionModulerelatedonDate+calculations

Hope it helps.

Regards,

AL

• ###### Re: Get the date of last year ?
Currently Being Moderated
honar wrote:

Experts,

>

> in my CMOD, we calulate previous year like this...... Date(4) = Date(4) -1.

> Til now it works gr8, but now, February 2012 has 29 days, so this logic fails.

> So, is there a FM which can calculate Previous year date ?

>

> So, if i input 2012/02/29 and the FM gives me 2011/02/28 ???

>

> thanks

You can use the function module.

```CALL FUNCTION 'CCM_GO_BACK_MONTHS'
EXPORTING
currdate = lv_date
backmonths = 1
IMPORTING
newdate = lv_new_date.```

Also, RP_CALC_DATE_IN_INTERNAL u2013 add/subtract year/month/days from a date

Hope that solves? Thanks!

Edited by: Arun Bala G on Feb 13, 2012 10:04 PM

• ###### Re: Get the date of last year ?
Currently Being Moderated

A very simple approach can be to put a check for month in your logic. Check if Month is Feb and then check if year will have 29 days and accordingly you can decide last year's date.

Regards,

Gaurav

• ###### Re: Get the date of last year ?
Currently Being Moderated
Gaurav Aggarwal wrote:

A very simple approach can be to put a check for month in your logic. Check if Month is Feb and then check if year will have 29 days and accordingly you can decide last year's date.

>

> Regards,

> Gaurav

Dear Gaurav, In this method, this would be valid only for 1 year, isn't it? And, next year there must a CR introduced again to remove that hard coding? Why use complex logic like calculate 1st if leap year, second subtract using some hardcoding etc & arrive a result. SAP standard function modules saves your time & effort, and even throws exceptions if required on the errors

• ###### Re: Get the date of last year ?
Currently Being Moderated

Pls try and check FM: RP_CALC_DATE_IN_INTERVAL