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 Comparision

Former Member
0 Likes
1,328

Can we Subtract Date for Ex. 21/07/2008 - 10/07/2008. ?

how can we solve this date ? please give me the code?

13 REPLIES 13
Read only

Former Member
0 Likes
1,299

Hi,

Yes you can Subtract date or Add Date.

You can also use FM.

Check this link

http://sap-abapinfo.blogspot.com/2008/03/sap-function-module-for-date-and-time.html

Regards,

Sujit

Read only

Former Member
0 Likes
1,299

you can always subtract or add a date to another , we use FM's to do this

try this FM's:

RP_CALC_DATE_IN_INTERVAL

Add/subtract years/months/days from a date

SD_DATETIME_DIFFERENCE

Give the difference in Days and Time for 2 dates

With luck,

Pritam.

Read only

Former Member
0 Likes
1,299

hi

use this FM

MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.

END_OF_MONTH_DETERMINE_2 : Determines the End of a Month.

HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.

FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.

Cheers

Snehi

Read only

Former Member
0 Likes
1,299

Hi,

check this.

HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.

FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.

SD_CALC_DURATION_FROM_DATETIME : Find the difference between two date/time and report the difference in hours

L_MC_TIME_DIFFERENCE : Find the time difference between two date/time

HR_99S_INTERVAL_BETWEEN_DATES : Difference between two dates in days, weeks, months

u can get all FM regarding dates in this thread

Read only

Former Member
0 Likes
1,299

Hi Bala,

Declare the date variables of type sy-datum and then directly subtract those two dates.

You will get the difference in no. of days

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
1,299

Hi bala,

Use the FM:-

*FIMA_DAYS_AND_MONTHS_AND_YEARS *

This will resolve your issue.

Best of luck,

Bhumika

Read only

anversha_s
Active Contributor
0 Likes
1,299

hi,

U can do like that, if u want more just try this.

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.

Regards,

Anversha

Read only

Former Member
0 Likes
1,299

Hi,

Please try using FM DAYS_BETWEEN_TWO_DATES.

Thanks,

Sriram POnna.

Read only

Former Member
0 Likes
1,299

hi,

Try using

HR_99S_INTERVAL_BETWEEN_DATES

Read only

Former Member
0 Likes
1,299

Hi,

U can use the below code for the date calculation... i hope will give to some help....

.

data: C_date like sy-datum,

P_date like sy-datum,

B_DATE TYPE DATUM,

E_DATE TYPE DATUM.

C_date = sy-datum.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = C_date

days = 00 "--> no of days date to be substracted

months = 1

SIGNUM = '-'

years = 00

IMPORTING

CALC_DATE = P_date.

write:/'Current date', C_date,

'Old date ', P_date.

CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'

EXPORTING

iv_date = P_DATE

IMPORTING

EV_MONTH_BEGIN_DATE = B_DATE

EV_MONTH_END_DATE = E_DATE.

write:/'Begin date', B_date,

'End date ', E_date.

you can use any of the above two functions to calculate the difference of two dates...

Thanks & Regards

Ashu Singh.

.

Read only

Former Member
0 Likes
1,299

Hi Bala.

I would like to suggest a few references,

[SDN - Reference for Calculating Difference between two dates in days|;

[SDN - Reference for Difference between dates|;

[SDN - Reference for Difference between two dates required in years and months|;

[SDN - Reference for calculate the number of days between dates : Date difference Calculation|;

[SDN SAP Note - 1213507 - Subtracting one date field from another to get the difference in days|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do]

[SDN - Reference for Function Module for difference between two dates|;

Hope that's usefull.

Good Luck & Regards.

Harsh Dave

Read only

former_member787646
Contributor
0 Likes
1,299

Hi

Try this...

DATA: date1 type d value '20080721',

date2 type d value '20080710',

date3 type d.

date3 = date1 -date2.

write:/ date3.

Hope it helps.

Murthy

Read only

Former Member
0 Likes
1,299

Hi Bala,

When you subtract two dates as you are doing in the example you posted. You will be getting the number of days between those dates.

So according to your requirement if you want to get the number of days months and years you can use the FM 'HR_GET_TIME_BETWEEN_DATES' or 'FI_PSO_FULL_DAY_MONTH_YEAR_GET'

Regards,

Swapna.