Former Member

# Calculate no days from two dates

Hi,

i want to create a calculated keyfigure to display no of days from two keyfigures ( A & B).

I am using the formula as CKF = b-a ( No of days)

If the value of a keyfigure is zero then system is displaying some odd number. Is there any better way to calculate difference between two numbers.

Regards,

Reddy.

10|10000 characters needed characters exceeded

### Related questions

Former Member
Posted on Aug 13, 2009 at 09:47 AM

Hi,

Say you have two date ranges From_date and To_date. now if both the values are noo zero then the formula (To_date - From_date) would work fine..but if one of the values is zero then you will have to decide upon some value to build the formula.

1. if To_dtae = 0

you can take the system date in that case. or the report execution date as To-date and build the formula using some boolean operatos.

2. if From_date = 0

here you need to decide the start date as some value of your interest say 01.01.2008 or depending on the transactions of the business data some value.(if you dont have the range value you cannot calculate the days).Apply the boolean operators and calculate the value for days.

Bhavna.

10|10000 characters needed characters exceeded
• Former Member
Posted on Aug 12, 2009 at 02:36 PM

Dates are calculated as no of days from a particular date (for SAP it is 01/01/1000 I think).

If one of the dates in calculation comes as zero, the result is going to be a large no (see above).

You may want to put a boolean multiplier to your formula to take care of situations where one date is zero. (What really do you want to see in say '20090812 minus zero'? You need to decide that and formulate accordingly.)

10|10000 characters needed characters exceeded
• Hi,

Use the following FM and calculate it. In your case you are telling that the dates are keyFigures, so ask ABAPer how to convert it to 0CALDAY formate then use the following FM. Better you load that Keyfigures data to Two ZDATE1 and ZDATE2 Time charecteristics and do the calculation.

/SDF/CMO_DATETIME_DIFFERENCE

Thanks

Reddy