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: 

trapped in date calculations

Former Member
0 Kudos

hi intelectuals

actually im pointing down certain issues tht im facin in date calculations in terms of examples.

1) subtracting 31/09/2006 and 25/08/2006.whats d output.

2) date is 12/09/2006.if i add 12(number) to it will it bcome 24/09/2006.or if i subtract 10 from it will it bcome 2/9/2006.

im not able to understand dese date calculations

hope i get d solution asap.

5 REPLIES 5

Former Member
0 Kudos

HI

> 1) subtracting 31/09/2006 and 25/08/2006.whats d

> output.

<b> Generally while doing the subtraction, date in past will be subtracted from date i.e latest

Here in your case it is 20060930 - 20060825 = returns the days in between.</b>

> 2) date is 12/09/2006.if i add 12(number) to it will

> it bcome 24/09/2006.or if i subtract 10 from it will

> it bcome 2/9/2006.

<b> Integer that is used to manipulate a date is treated as the number of days for addition or subtraction.</b>

Lastly my friend there is no 31st in the month of September.

Kind Regards

Eswar

Clemenss
Active Contributor
0 Kudos

Hi vishwanath,

in ABAP the operators + and - are defined to work with data type D (date). That means, you add or subract the number of days to (or from) a given date and get the resulting date according to our (gregorian) calendar.

Subtracting an earlier from a later date gives the number of days between. The resulting variable shoul be numeric, not date:

<pre>

data:

lv_dat1 type sy-datum value '20060930',

lv_dat2 type sy-datum value '20060825',

lv_int type i .

lv_int = lv_dat1 - lv_dat2.

</pre>

results in 36 (days) for variable lv_int.

Note:

31/09/2006 is not valid as september is defined with 30 days (ABAP knows!).

Regards,

Clemens

Former Member
0 Kudos

Hi,

1). subtracting 31/09/2006 and 25/08/2006.whats d output?

Number of days will be given.

2). date is 12/09/2006.if i add 12(number) to it will it bcome 24/09/2006.or if i subtract 10 from it will it bcome 2/9/2006?

To get this u can also use FM 'RP_CALC_DATE_IN_INTERVAL' in which you can pass the number of days in 'days' and + or - in 'signum'.

Hope this migh thelp u.

Thanks,

Prashanth

Former Member
0 Kudos

The output of difference between two dates returns the number of days between the two. So the result is number of days.

Secondly when you add or subtract a number from a date field it considers the number to be days and does the required addition or subtraction.

Regards

Anurag

Former Member
0 Kudos

Hi,

1) subtracting 31/09/2006 and 25/08/2006.whats d

output.

system stores date in format 20060931(yyyymmdd)

and subtracts 20060825 to return no of days

between them i.e 36

2) lv_date = sy-datum + 12 will add 12 days to system

date.

lv_date = 20061009 + 12 = 20061021.

Regards

amole