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: 

Problem with the Date

Former Member
0 Kudos
105

HI frendz,

I have to retrieve data considering the date range.I have to check a date in the where condition which should within the last 12 months.So my one interval will be sydatum but how can i get the other interval ie 1 year back date ?? Is there any std function module which gives one year back date if we give the present date. Pls help me out in this ASAP...

10 REPLIES 10

jayanthi_jayaraman
Active Contributor
0 Kudos
80

Hi,

Use date_in_future . Give the date in Import_datum parameter and give -365 in anzahl_tage .You can see the output.But for leap year , you need to take care.

andreas_mann3
Active Contributor
0 Kudos
80

hi,

try that:

yr_back_date = sy-datum .

SUBTRACT 1 FROM yr_back_date+3(1).

regards Andreas

Former Member
0 Kudos
80

hi

try this

CALL FUNCTION 'BKK_ADD_MONTH_TO_DATE'

EXPORTING

months = -12

olddate = sy-datum

IMPORTING

NEWDATE = dt_new

.

dt_new gives u a 12 month previous date

check out my reply in this post for some more function modules...

https://www.sdn.sap.com/sdn/collaboration.sdn?node=linkFnode6-1&contenttype=url&content=https://

regards,

PJ

0 Kudos
80

oops !!

sorry i led u to the wrong post...

here are some more function modules...

RE_ADD_MONTH_TO_DATE

HR_JP_ADD_MONTH_TO_DATE

/BEV4/PLPS__ADD_MONTH_TO_DATE

/BEV3/CHPS__ADD_MONTH_TO_DATE

there are more....u can search...

regards,

PJ

0 Kudos
80

Hello Priyank,

I am not able to access any one of the function modules which you mentioned.

My requirement is to do operations on date. How can I achive it ?

For example I need to add 2years 3months 4 days to current date and similarly I need suggestions about operations on time.

Thanks in advance.

Regards,

Arvind...

0 Kudos
80

hi,

try with this fm HR_SEN_CALE_DAYS_DATE

cheers,

sasi

Former Member
0 Kudos
80

Hi Nagarjuna,

In general, when we say the data one year back, we take the date one day after the current date and one year before the current year -

For example - If today is 22nd July 2005, one year back, the date should be taken as 23rd july 2004.

Look at the following snippet of code -


PARAMETERS : PRESENT TYPE D.

DATA : BEGIN OF PAST_DATE,
         YEAR(4)  TYPE N,
         MONTH(2) TYPE N,
         DAY(2)   TYPE N,
       END OF PAST_DATE.
DATA : ONE_YEAR_BACK TYPE D.

MOVE PRESENT TO PAST_DATE.

SUBTRACT 1 FROM PAST_DATE-YEAR.
ADD 1 TO PAST_DATE-DAY.
MOVE PAST_DATE TO ONE_YEAR_BACK.

hope that helps.

Regards,

Anand Mandalika.

0 Kudos
80

Hi PJ,

your function module looks like the best solution.

Andreas, what happens, when your calculation starts on 20040229? -> 20030229?!

Anand Mandalika, you are not longer calculation on date fields, I tried 20050731 -> 20050732!

Regards,

Christian

0 Kudos
80

O.K. Christian,

IF datum+4 = '0229'.
  yr_back_date = datum - 1.
ELSE.
  yr_back_date = datum .
ENDIF.

SUBTRACT 1 FROM yr_back_date+3(1).

Andreas

0 Kudos
80

Hi,

Christians comment on Anand Mandalika's code is correct.

Since Dates are only integers with a mask the code can be corrected as follows:

PARAMETERS : PRESENT TYPE D.

DATA : BEGIN OF PAST_DATE,

YEAR(4) TYPE N,

MONTH(2) TYPE N,

DAY(2) TYPE N,

END OF PAST_DATE.

DATA : ONE_YEAR_BACK TYPE D.

MOVE PRESENT TO PAST_DATE.

SUBTRACT 1 FROM PAST_DATE-YEAR.

MOVE PAST_DATE TO ONE_YEAR_BACK.

ADD 1 TO ONE_YEAR_BACK.

Message was edited by: Erik Verbeeck