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 calculations

Former Member
0 Likes
11,294

Hi all. I want to perform some calculations on DATE.

Say for eg. I want to calculate a date 100 days before the current date or say a date 250 days ahead of todays date. Is there a function module for that?

PLEASE give some sample code for the function module - how to use that FM.

Thanks

Ribhu

Hi all. I want to perform some calculations on DATE.

Say for eg. I want to calculate a date 100 days before the current date or say a date 250 days ahead of todays date. Is there a function module for that?

PLEASE give some sample code for the function module - how to use that FM.

Thanks

Ribhu

8 REPLIES 8
Read only

Former Member
0 Likes
4,726

Hi,

You can use just addition or subtraction on data types of D

check this example.



DATA: V_DATE TYPE SYDATUM.

V_DATE = SY-DATUM.   " current date.

* Move to 100 days before.
V_DATE = V_DATE - 100.

WRITE: / v_date.    " 100 days before.

V_DATE = SY-DATUM.

* Move to 250 days after.
V_DATE = V_DATE + 250.

WRITE: / v_date.    " 250 days after.

Thanks

Naren

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
4,726

Hi,

Use FM 'DATE_IN_FUTURE'.

For previous period,

ANZAHL_TAGE <b>-</b>30

IMPORT_DATUM 23.06.2007

For future period,

ANZAHL_TAGE <b>+</b>30

IMPORT_DATUM 23.06.2007

Message was edited by:

Jayanthi Jayaraman

Read only

0 Likes
4,726

Hi Jayanthi,

I think I saw some of ur white papers on smartforms b4 . My g mail address is [email protected] . Whats ur g mail address?

One concern - suppose I wanna find a date 200 months back the current date or any date stored in a variable - how to do that??

Thanks

Ribhu

Read only

0 Likes
4,726

hi,

Just execute this sample report.

data : wa_date type sy-datum.
 
call function 'RP_CALC_DATE_IN_INTERVAL'
exporting
date = sy-datum
days = 0 " --------------------> give ur required date
months = 200 "--------------------> give ur required month
years = 0 " --------------------> give ur required years
signum = '-'
importing
calc_date = wa_date.
 
write :/ wa_date. " new minised date

Rgds

Anversha

Read only

Former Member
0 Likes
4,726

Hi Ribhu,

Calculation on dates can be just done as arithematic calculation in SAP.

For e.g

data date type sy-datum.

date = sy-datum - 15.

will give you a date 15 days before the current date.

Reward points if useful.

Regards,

Atish

Read only

Former Member
4,726

here is the sample code for your exactly for 100 days before .

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.

EDAYS = EDAYS .
WRITE:/ 'Difference in Days   ', EDAYS.
*WRITE:/ 'Difference in Months ', emonths.
*WRITE:/ 'Difference in Years  ', EYEARS.

INITIALIZATION.
FROMDATE = SY-DATUM - 100 .

reward points if it is usefull ..

Girish

Read only

anversha_s
Active Contributor
0 Likes
4,726

hi,

use this FM.

data : wa_date type sy-datum.
 
call function 'RP_CALC_DATE_IN_INTERVAL'
exporting
date = sy-datum
days = 20 " --------------------> give ur required date
months = 0 "--------------------> give ur required month
years = 0 " --------------------> give ur required years
signum = '-'
importing
calc_date = wa_date.
 
write :/ wa_date. " new minised date
 
"Note
"signum = '+' " 
"signum = '-' "

Rgds

Anversha

Read only

Former Member
0 Likes
4,726

hi ribhu,

use this function module 'SD_DATETIME_DIFFERENCE' hope this may help u...

please reward incase usefull...

regards,

prashant