Former Member

# Difference between dates

Hi,

How to find the diffrence between two dates in terms of years. i mean how many years gap is there between tow dates.

sudheer.A

10|10000 characters needed characters exceeded

### Related questions

Former Member
Posted on Jul 27, 2007 at 07:32 AM

Hi Sudheer,

Just simple use 'FIMA_DAYS_AND_MONTHS_AND_YEARS' and E_YEARS will get you the difference in years.

Regards,

Younus

10|10000 characters needed characters exceeded
• Posted on Jul 27, 2007 at 03:57 AM

Hello Sudheer

If you have class <b>CL_RECA_DATE</b> available in your system you can call its static method <b>GET_DATE_DIFF</b>.

Regards

Uwe

10|10000 characters needed characters exceeded
• Former Member
Posted on Jul 27, 2007 at 03:53 AM

Hi,

REPORT ZDATEDIFF.

DATA: EDAYS LIKE VTBBEWE-ATAGE,

EMONTHS LIKE VTBBEWE-ATAGE,

EYEARS LIKE VTBBEWE-ATAGE.

PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,

TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.

call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

exporting

i_date_from = FROMDATE

i_date_to = TODATE

• I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS

E_YEARS = EYEARS.

WRITE:/ 'Difference in Days ', EDAYS.

WRITE:/ 'Difference in Months ', EMONTHS.

WRITE:/ 'Difference in Years ', EYEARS.

INITIALIZATION.

FROMDATE = SY-DATUM - 60.

also check out the below program to fine date difference

data: d1 like sy-datum,

d2 like sy-datum.

data: diff type i.

d1 = '20060331'.

d2 = '20060220'.

diff = d1 - d2.

write : / diff .

Also chek these FMs:

'CSCP_PARA1_GET_PERIODS'

HR_99S_INTERVAL_BETWEEN_DATES(Months, Years and days)

COMPUTE_YEARS_BETWEEN_DATES

EHS_CALC_YEARS_BETWEEN_DATES

DAYS_BETWEEN_TWO_DATES

MONTHS_BETWEEN_TWO_DATES

For No of week days between two dates please check out the below program it might help you

report zrich_0003.

data: begin of itab occurs 0,

datum type sy-datum,

end of itab.

data: weekday like dtresr-weekday.

data: number_lines type i.

parameters: p_sdatum type sy-datum,

p_edatum type sy-datum.

itab-datum = p_sdatum.

append itab.

do.

if itab-datum = p_edatum.

exit.

endif.

itab-datum = itab-datum + 1.

call function 'DATE_TO_DAY'

exporting

date = itab-datum

importing

weekday = weekday.

if weekday = 'Sat.'

or weekday = 'Sunday'.

continue.

endif.

append itab.

enddo.

describe table itab lines number_lines.

write:/ 'Number of days between dates is', number_lines.

-

http://help.sap.com/saphelp_webas620/helpdata/en/fc/eb3509358411d1829f0000e829fbfe/frameset.htm

10|10000 characters needed characters exceeded
• Former Member
Posted on Jul 27, 2007 at 03:58 AM

Hi,

https://forums.sdn.sap.com/click.jspa?searchID=3361043&messageID=2373018

You can use <b>FIMA_DAYS_AND_MONTHS_AND_YEARS</b>

See the below code for ur refrence:

REPORT ZDATEDIFF.

DATA: EDAYS LIKE VTBBEWE-ATAGE,

EMONTHS LIKE VTBBEWE-ATAGE,

EYEARS LIKE VTBBEWE-ATAGE.

PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,

TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.

call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

exporting

i_date_from = FROMDATE

i_date_to = TODATE

• I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS

E_YEARS = EYEARS.

WRITE:/ 'Difference in Days ', EDAYS.

WRITE:/ 'Difference in Months ', EMONTHS.

WRITE:/ 'Difference in Years ', EYEARS.

INITIALIZATION.

FROMDATE = SY-DATUM

<b>Reward points if useful</b>

Regards

Ashu

10|10000 characters needed characters exceeded
• Former Member
Posted on Jul 27, 2007 at 04:03 AM
`" Here is the  program link `

reward points if it is usefull ...

Girish

10|10000 characters needed characters exceeded
• Posted on Jul 27, 2007 at 05:55 AM

Just check this this code will give you the exact years,months and days between two dates...please reward if usefull

DATA : wk_date1 LIKE sy-datum VALUE '20070717', "End date

wk_date2 LIKE sy-datum VALUE '19951201', "Start date

wk_day1(2) TYPE c,

wk_day2(2) TYPE c,

wk_day3(2) TYPE c,

wk_month1(2) TYPE c,

wk_month2(2) TYPE c,

wk_month3(2) TYPE c,

wk_year1(4) TYPE c,

wk_year2(4) TYPE c,

wk_year3(4) TYPE c.

wk_year1 = wk_date1(4).

wk_year2 = wk_date2(4).

wk_month1 = wk_date1+4(2).

wk_month2 = wk_date2+4(2).

wk_day1 = wk_date1+6(2).

wk_day2 = wk_date2+6(2).

wk_day3 = wk_day1 - wk_day2.

wk_month3 = wk_month1 - wk_month2.

wk_year3 = wk_year1 - wk_year2.

*****Month and year calculation

IF wk_month3 < 0.

wk_year3 = wk_year3 - 1.

wk_month3 = 12 + wk_month3.

ELSEIF wk_month3 = 0 AND wk_day3 < 0.

wk_year3 = wk_year3 - 1.

ENDIF.

********Day calculation.

if wk_day3 < 0.

data: last_month_last_day type sy-datum.

last_month_last_day = wk_date1.

last_month_last_day+6(2) = '01'.

last_month_last_day = last_month_last_day - 1.

clear wk_day1.

wk_day1 = last_month_last_day+6(2).

wk_day3 = wk_day3 + wk_day1.

endif.

WRITE : 'Days : ', wk_day3,

/ 'Months : ', wk_month3,

/ 'Years : ', wk_year3.

10|10000 characters needed characters exceeded
• Former Member
Posted on Jul 27, 2007 at 06:23 AM

data: from_years(4) type n,

to_years(4) type n,

diff(4) type n.

parameters: p_from type d,

p_to type d.

from_years = p_from+0(4).

to_years = p_to+0(4).

diff = from_years - to_years.

write: diff.

10|10000 characters needed characters exceeded
• Former Member
Posted on Jul 27, 2007 at 06:24 AM

data: from_years(4) type n,

to_years(4) type n,

diff(4) type n.

parameters: p_from type d,

p_to type d.

from_years = p_from+0(4).

to_years = p_to+0(4).

diff = from_years - to_years.

write: diff.