Application Development and Automation 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: 
Read only

DATE filed Operations....

Former Member
0 Likes
840

hi friends,

When I subtract date1 from date2 I need no. of days and no. of months and no. of years.

Example (1):

date1 : 12.08.2005

date2 : 22.08.2005

answer should be like this. (date2 minus date1)

Days : 10

Months : 0

Years: 0

thanks in advance.

1 ACCEPTED SOLUTION
Read only

athavanraja
Active Contributor
0 Likes
685

use FM

FIMA_DAYS_AND_MONTHS_AND_YEARS

just pass i_date_from and i_date_to

Regards

Raja

Message was edited by: Durairaj Athavan Raja

hi friends,

When I subtract date1 from date2 I need no. of days and no. of months and no. of years.

Example (1):

date1 : 12.08.2005

date2 : 22.08.2005

answer should be like this. (date2 minus date1)

Days : 10

Months : 0

Years: 0

thanks in advance.

4 REPLIES 4
Read only

athavanraja
Active Contributor
0 Likes
686

use FM

FIMA_DAYS_AND_MONTHS_AND_YEARS

just pass i_date_from and i_date_to

Regards

Raja

Message was edited by: Durairaj Athavan Raja

Read only

0 Likes
685

above solution looks better, except the year is 1 when you have the same year.

I build something like this, its not that nice maybe but it works

DATA: dat1 like sy-datum value '20051110',

dat2 like sy-datum value '20051205',

day_nr type i,

mon_nr type i,

yr_nr type i.

day_nr = dat2 - dat1.

mon_nr = dat24(2) - dat14(2).

yr_nr = dat20(4) - dat10(4).

write: / 'day(s): ',day_nr.

write: / 'month(s): ', mon_nr.

write: / 'year(s): ', yr_nr.

Read only

0 Likes
685

hi raja,

its giving total no. of days and total no. of months and total no. of years.

but i need different manner. i.e.

from date : 22.07.2003

to date : 10.03.2005

the result should be like this.

days : 12

months: 4

years :2

thanks in advance

Read only

0 Likes
685

then it will be this

DATA: dat1 like sy-datum value '20030722',

dat2 like sy-datum value '20050310',

day_nr type i,

mon_nr type i,

yr_nr type i.

day_nr = abs( dat26(2) - dat16(2) ).

mon_nr = abs( dat24(2) - dat14(2) ).

yr_nr = abs( dat20(4) - dat10(4) ).

write: / 'day(s): ',day_nr.

write: / 'month(s): ', mon_nr.

write: / 'year(s): ', yr_nr.

Message was edited by: Peter van Alphen