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 field manipulation

Former Member
0 Likes
2,747

How to add 5 months to date field.

For ex: To find out the date after 5 months from today.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,277

Hi,

Use the following function module:

MONTH_PLUS_DETERMINE :Add or subtract months from a date. To subtract a month, enter a negative value for the 'months' parameter.

Example:

data: new_date type d.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = -5 " Negative to subtract from old date, positive to add

olddate = sy-datum

IMPORTING

NEWDATE = new_date.

write: / new_date.

Regards,

Shiva Kumar

12 REPLIES 12
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,277

USE FUNCTIONAL MODULE

HR_PSD_DATES_ADD_MONTHS

Read only

Former Member
0 Likes
2,278

Hi,

Use the following function module:

MONTH_PLUS_DETERMINE :Add or subtract months from a date. To subtract a month, enter a negative value for the 'months' parameter.

Example:

data: new_date type d.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = -5 " Negative to subtract from old date, positive to add

olddate = sy-datum

IMPORTING

NEWDATE = new_date.

write: / new_date.

Regards,

Shiva Kumar

Read only

Former Member
0 Likes
2,277

hi there...

i hav seen this qstn many a times and the ways people devise to get past this. But i dont understand y dont u look for better and easier ways of getting over problems.

Anyways, i would suggest you to declare a variable of type p and put in the date in it. Then simply add the number of days to this. This will solve your query. I am not putting in the entire code, as i dont feel it will be in your interest. Try going ahead with this much hint and u wil find your way out.

Do reward if helpful or get back if still facing any issues.

Read only

0 Likes
2,277

hi prem,

how do u know that how many days to add.

the no. of days in a month can change for ex: for FEB

and when u dont know on which day you will run the program, then how do u calculate the no.of days

Read only

Former Member
0 Likes
2,277

Hi,

Call function 'BCA_US_DATES_CALC_DATE'

exporting i_start_date = <old_date>

i_term = <month>

i_periodunit = '3'

importing e_end_date = <new_date>

Cheers.

...Reward if useful.

Read only

prasanth_kasturi
Active Contributor
0 Likes
2,277

hi,

use the fm

DATE_IN_FUTURE : Calculate a date N days in the future.

Program:

PARAMETERS: p_days TYPE i, " Number days that are added/subtracted

p_date TYPE eeind. " Date to which NUMBER_DAYS is added

DATA: addin_date TYPE sy-datum, " Determined date in the internal format

addex_date(10) TYPE c. " Determined date in external format

CALL FUNCTION 'DATE_IN_FUTURE'

EXPORTING

anzahl_tage = p_days

import_datum = p_date

IMPORTING

export_datum_ext_format = addex_date

export_datum_int_format = addin_date.

WRITE:/5 'date in the internal format: ', addin_date ,

/5 'Determined date in external:', addex_date.

MONTH_PLUS_DETERMINE - Add or subtract months from a date. To subtract a month, enter a negative

parameters: date type SYDATUM, " date

months type i. " no of months to add/subtract ,

  • use '-' for subtraction.

data: newdate type SYDATUM.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = months

olddate = date

IMPORTING

NEWDATE = newdate

.

write:/ 'old date:', date.

write:/ 'new date:', newdate.

regards

prasanth

Read only

Former Member
0 Likes
2,277

Hi,

look at the Below FM's, you can use one of those..

MONTH_PLUS_DETERMINE--> Add or subtract months from a date. To subtract a month, enter a negative value for the 'months' parameter.

codedata: new_date type d.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'

EXPORTING

months = 5

olddate = sy-datum

IMPORTING

NEWDATE = new_date.

write: / new_date.[/code]

You can use RE_ADD_MONTH_TO_DATE also

You can Also use the FM 'RP_CALC_DATE_IN_INTERVAL'

sample code

data: date like sy-datum,

date1 like sy-datum.

date = sy-datum.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = date

days = 00

months = 02 "no of months

SIGNUM = '+' "months added

years = 00

IMPORTING

CALC_DATE = date1. " new date

write:/ 'new date', date1.[/code]

Regards,

Raj.

Read only

Former Member
0 Likes
2,277

Hi,

Use any of the following function modules.

SG_PS_ADD_MONTH_TO_DATE Add months to the date

MONTH_PLUS_DETERMINE Add months to the date

BKK_ADD_MONTH_TO_DATE Add months to the date

RE_ADD_MONTH_TO_DATE Add months to the date

HR_PSD_DATES_ADD_MONTHS Add months to the date

HR_HCP_ADD_MONTH_TO_DATE Add months to the date

HR_JP_ADD_MONTH_TO_DATE Add months to the date, Minus months from date

HR_BR_ADD_MONTH_TO_DATE Add months to the date, Minus months from date

HR_PT_ADD_MONTH_TO_DATE Add months to the date, Minus months from date

Read only

Former Member
0 Likes
2,277

Hi,

You can use FM RP_CALC_DATE_IN_INTERVAL, input your date in date, months - no. of mnths to be increased, signum to be '+'.

Thanks,

Sriram Ponna.

Read only

peter_ruiz2
Active Contributor
0 Likes
2,277

hi charan,

just add 5 to your date field.

for example:

v_date = '20080519'. "today's date in YYYYMMDD

v_date = v_date+4(2) + 5.

regards,

Peter

Read only

former_member386202
Active Contributor
0 Likes
2,277

Hi,

Use FM

RE_ADD_MONTH_TO_DATE

Regards,

Prashant

Read only

Former Member
0 Likes
2,277

This message was moderated.