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: 

how to subtract date

Former Member
0 Kudos

hi friends

i had a current date which is 20090730 , which i want to minus in 20090730.

and i want output in same format , so can u suggest me any function module.

i dont want any month and time calculation in it. simply i want to minus date to date.

thanks

10 REPLIES 10

Former Member
0 Kudos

You can simply minus date.

l_datum = sy-datum -1.

But there are many FM for date calculation,

CALCULATE_DATE Calculates the future date based on the input .

DATE_TO_DAY Returns the Day for the entered date.

DATE_COMPUTE_DAY Returns weekday for a date

DATE_GET_WEEK Returns week for a date

RP_CALC_DATE_IN_INTERVAL Add days / months to a date

DAY_ATTRIBUTES_GET Returns attributes for a range of dates specified

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.

MONTH_NAMES_GET Get the names of the month

WEEK_GET_FIRST_DAY Get the first day of the week

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

LAST_DAY_OF_MONTHS Returns the last day of the month

DATE_CHECK_PLAUSIBILITY Check for the invalid date.

DATE_2D_TO_4D_CONVERSION Year entry: 2-character to 4-character.

DAY_IN_WEEK Input date and will give the name of the day 1-monday,2-Tuesday....

SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2 dates

0 Kudos

sorry for my mistake, actually my date is 20090724 and i want to minus date 20090312

how will i do?, and i want output as .

ex: 20090724

- 20090312

ans = 20090412. not getting the output as desired.

0 Kudos

Hi,

So, what you want is the mid-point between two dates? The advice you've been given so far (and would easily have found if you search the forum first) is enough to get your answer.

Subtract one date from the other to get the difference in days, divide this number by 2 and add it to the lowest date.

Regards,

Nick

0 Kudos

Hi

If you substract two dates you'll obtain an integer number: the difference beetween two date:

DATA: days TYPE i,
           dat_1 TYPE sy-datum VALUE '20090724',
           dat_2 TYPE sy-datum VALUE '20090312'.

days = dat_1 - dat_2.

WRITE days.

Days is equal to 134, because 134 are the days beetween 12/03/2009 and 24/07/2009: do u need this?

Max

former_member194416
Contributor
0 Kudos

Hi,

Can you give an example about your calculation ?

like 20091705 - 20071203 = ? What you expect result to be ?

0 Kudos

sorry for my mistake, actually my date is 20090724 and i want to minus date 20090312

how will i do?, and i want output as .

ex: 20090724

- 20090312

ans = 20090412. not getting the output as desired.

0 Kudos

try using Fm : 'FIMA_DAYS_AND_MONTHS_AND_YEARS' and get the date and them minus the number of days ..

0 Kudos

no need of using any FM for subtracting days.

declare a date variable gv-date type sy-datum.

and then

gv_date = date1 - date2.

write gv_date.

Former Member
0 Kudos

Hi,

if you want the minus sign infront of date...then move the date to char field with length of 9 and concatenate negative sign infront of the date.

if above does not serve your purpose .....Can you explain with example..

Former Member
0 Kudos

you can directly use like 12072009 - 12072008 , it will work in SAP.