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

fm for previous date

Former Member
0 Likes
3,929

Hi,

Is any FM is there which can calculate the previous 1 year date or more.

Suppose I have today's date & based on that date I wanted to calculate the previous 1 year date.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,789

Try even in this way

data: prev_date like sy-datum.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = sy-datum
days = 3
months = 0
signum = '-'
years = 0
IMPORTING
calc_date = prev_date.


write:/ prev_date.

7 REPLIES 7
Read only

Former Member
0 Likes
2,789

Hi Neha,

No need to go for any FM,

Just use like this

data last_date type d.

last_date0(4) = sy-datum0(4) - 1.

last_date4(4) = sy-datum4(4).

Regards,

Atish

Read only

Former Member
0 Likes
2,789

hi Neha,

Use the following FM for getting the year and the month based on date

CACS_DATE_GET_YEAR_MONTH

Regards,

Santosh

Read only

Former Member
0 Likes
2,790

Try even in this way

data: prev_date like sy-datum.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = sy-datum
days = 3
months = 0
signum = '-'
years = 0
IMPORTING
calc_date = prev_date.


write:/ prev_date.

Read only

Former Member
0 Likes
2,789

Hi Neha,

here is the function module. Which you can use to get any month date and year.

RP_CALC_DATE_IN_INTERVAL

Hope this will help you out.

Rewards if helpful.

Regards

Azad.

If any query tell me.

Read only

Former Member
0 Likes
2,789

HI,

Start date would be 01 for every month, so to find the last date for a month use RP_LAST_DAY_OF_MONTHS function module

Or

Please try this.

data: wa_date like sy-datum,

s_date like sy-datum,

e_date like sy-datum.

wa_date = sy-datum - 30.

CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'

EXPORTING

iv_date = wa_date

IMPORTING

ev_month_begin_date = s_date

ev_month_end_date = e_date.

<b>Reward points</b>

Regards

Read only

Former Member
0 Likes
2,789

Hi,

<b>DATE_CHECK_PLAUSIBILITY</b>- Check to see if a date is in a valid format for SAP. Works well when validating dates being passed in from other systems.

<b>DATE_COMPUTE_DAY</b>- Returns a number indicating what day of the week the date falls on. Monday is returned as a 1, Tuesday as 2, etc.

<b>DATE_GET_WEEK</b> -will return the week that a date is in.

<b>DATE_IN_FUTURE</b>- Calculate a date N days in the future.

<b>DAY_ATTRIBUTES_GET</b> - Return useful information about a day. Will tell you the day of the week as a word (Tuesday), the day of the week (2 would be Tuedsay), whether the day is a holiday, and more.(provided by Francois Henrotte)

F4_DATE displays a calendar in a popup window and allows user to choose a date, or it can be displayed read only.

Pls find any FM useful to u.

Pls reward helpful points.

Regards,

Ameet

Read only

Former Member
0 Likes
2,789

Hi,

Please check this code and change the number of years or months or days as per your requirement :

data : date type sy-datum, out_date type sy-datum.

date = '20070702'.

CALL FUNCTION 'J_1H_CAL_DATE_IN_INTERVAL'

EXPORTING

date = date

days = '00'

months = '00'

SIGNUM = '-'

years = '01'

IMPORTING

CALC_DATE = out_date.

write 😕 out_date.

Reward points, if helpful,

Sandeep Kaushik