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 between two dates

Former Member
0 Likes
3,910

Hi,

I've searched the whole SDN but i could not find the answer for this.

I want to substract two dates and get the return value as a date only.

For example:

Data : v_date1 type sy-datum default '20090702',

v_date2 type sy-datum default '20090602',

v_date TYPE sy-datum.

After the execution of below code,

v_date = v_date1 - v_date2.

I get the value for v_date as 0.

And if i take the v_date as type I, it is giving me the differennce in dates but not a Date.

I want to get the difference as date only such as 20090702.

Please help me to get this.

Thanks,

Shamim

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,325

Hi,

This is not possible to get the date by subtracting the two different date. If you can provide the output then it is easy to provide any help.

14 REPLIES 14
Read only

Former Member
0 Likes
2,326

Hi,

This is not possible to get the date by subtracting the two different date. If you can provide the output then it is easy to provide any help.

Read only

Former Member
0 Likes
2,325

Well, on the surface, it's hard to see what you are trying to do. The difference between two dates is not a date. It is an integer number of days.

Can you expand on your requirement?

Rob

Read only

0 Likes
2,325

yeah that's right.

Difference b/w two dates is an integer value in general.

But i need to have a date when i'm subtracting two dates. Yes I can assure that the dates which i'm going to subract will never fall in the same month.

Always, the two dates will have difference months.

Thanks,

Shamim

Read only

0 Likes
2,325

>

> Difference b/w two dates is an integer value in general.

In general??

Please provide an example.

Rob

Read only

0 Likes
2,325

when i'm subtracting two dates such as 20090701 (sy-datum) and 20090702 (p_date).

v_date = sy-datum - p_date.

value in the variable v_date will be 1.

My requirement is to delete records from a custom table which are older than 6 months. So, for this, i'm creating one custom report whose selection paramter will be a date.

I'm subracting this with the system date and then passing the resultnt date to the "Select" statement.

Also, before executing the select statement, i've defined a constant c_months as 6

I want to calculate the month after subtracting the resultantt date such as v_months = resultatntdate+0(4).

Then i ll check if this month is greater than the constant month.

if v_months GT c_months.

Select * from customtable into an internal table

where entry_date LE resultantdate.

Elseif.

EXIT.

ENDIF.

please let me know if you have any other suggestions.

Thanks,

Shamim

Read only

0 Likes
2,325

So you don't want to subtract a date form a date, you just want to subtract 6 months from a date (find a date six months in the past).

Correct?

Rob

Read only

0 Likes
2,325

Nop, i want to substract a date from date just to have a resultant date which i can pass it in the data selection(SELECT statement).

From the resultant date, I'll also get the month which I'll compare it with the contant month i.e. 6 months.

If the comparision is greater than 6 months, then i'll execute the select statement and then delete the records from the custom table, else i'll exit.

*Check if the entry month is GT 6 months

IF v_diff_days GT c_days.

*Read data from the staging table based on the calculated date

SELECT * FROM yeim_clasfn_stg INTO TABLE i_yeim_clasfn_stg

WHERE entry_date LE v_resultant_date

IF sy-subrc = 0.

*Delete the read data from the staging table

DELETE yeim_clasfn_stg FROM TABLE i_yeim_clasfn_stg.

ENDIF.

ELSEIF v_diff_days LE c_days.

*Display an error message "Purging data of age less than 6 months is not possible.".

MESSAGE i004.

ENDIF.

Thanks,

Shamim

Read only

0 Likes
2,325

Sorry it still doens't make any sense for me. Arithmetically what date will be the result of below operation according to your calculation logic ?

v_date = 20090112 - 20080320.

Edited by: Gungor Ozcelebi on Jul 2, 2009 7:01 PM

Read only

0 Likes
2,325

Hi,

This is impossible to get the date by subtracting two dates. I think you should explain us with taking example dates..

Read only

0 Likes
2,325

use Function HR_HK_DIFF_BT_2_DATES. give your 2 dates as is, and use output_format = '04'. that will give the difference in months with decimals, and you need the difference to be > 6.

Read only

Former Member
0 Likes
2,325

Hi,

if u want to know the difference between 2 dates, try to use this FM

HR_GET_TIME_BETWEEN_DATES

I have used before and it works fine.

Regards.

Read only

Former Member
0 Likes
2,325

If I understand you correctly, you are looking for a date in the past of 60 days, for example. Look at FM HR_SEN_CALE_DAYS_DATE where ID_DATE is your date you wish to subtract from, ID_OPERATOR is and IS_DURATION you can indicate the Years, Months, and/or Days you wish to use to make your calculation with (in this case 60 days).

Read only

Former Member
0 Likes
2,325

Hi,

I can't understand ur requirement clearly.

But you you can easily convert any integer into Date.

Just move the integer value into a fiield of having data type D.

For example:

Data: d type d,

p type p,

d1 type d.

d = sy-datum." jul 03, 2009

p = d.

" now the d will have the total no of days from the very firt day of first year(0001). value will be ' 733592' days.

d1 = p.

write: d1. you will get the date.

Regards,

Ravi.

Read only

Former Member
0 Likes
2,325

thanks everybody.

It seems it is impossible to get a date after substracting two dates. We should create one FM for this, i think.

Anyway, i've resolved my issue.

Thanks again,

Shamim