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: 

how to find the previous months date from teh current date

Former Member
0 Kudos

Dear All,

Am working on a 3.1 i version.

Please let me know how i need to find the previous months date from the current date.

i mean current date- 1 month .

This logic will work.

data : w_date like sy-datum.

w_date = sy-daum.

"The statement below will work for everything....

w_date = w_date - 30.

write w:date.

But please tell me how thisis to be handled in case of today.

today being 30th march ,how do i find the one month old date.

Regards,

Abaper.

10 REPLIES 10

Former Member
0 Kudos

Hi,

Use the FM 'CALCULATE_DATE' if it exists in your version.

Regards,

Bhupal

former_member156446
Active Contributor
0 Kudos

check if this FM exists in ur system: HR_99S_DATE_ADD_SUB_DURATION

rainer_hbenthal
Active Contributor
0 Kudos

Set the day of your date field to '01' and subtract then 1 from the date. Now you will have the month in the5th and 6th position without taking care of leap years and year end problems.

Former Member
0 Kudos

Am sorry.

Both the above mentioned FMs do not exisit on 3.1i system :-(.

Regs,

Abaper

0 Kudos

Its not suitable for every condition...

DATA : w_date LIKE sy-datum.

w_date = sy-datum.

w_date+4(2) = w_date+4(2) - 1.

WRITE: sy-datum, / w_date.

0 Kudos

Are you sure this is working for January?

Heres mine:


wa_date+6(2) = '01'.
wa_date = wa_date - 1.
write:/ wa_date+4(2).

Works with leapyears and years end/start.

Edited by: Rainer Hübenthal on Mar 30, 2009 3:06 PM

faisal_altaf2
Active Contributor
0 Kudos

Hi,

Use FM NUMBER_OF_DAYS_PER_MONTH_GET to get Total number of days in any month of year.

than Minus these from your date using your logic above.

Hope this will solve out your Problem,

Best Regards,

Faisal

Former Member
0 Kudos

hi ,

Use this function module to get last month date..



CAll Function 'HR_PT_ADD_MONTH_TO_DATE'

DMM_DATIN                       20080202      "The date u want to pass  
DMM_COUNT                       1                "Number of months you want to deduct
DMM_OPER                        -                 " Subtract opertaor
DMM_POS                                                                                
*    The Output
                                           
Export parameters               Value          
                                               
DMM_DAOUT                       20080102       

Regards,

Prabhudas

Former Member
0 Kudos

Am sorry.

Both the above mentioned FMs do not exisit on 3.1i system :-(.

Regs,

Abaper

Former Member
0 Kudos

hi all,

This does not work for todays date 30-03-2009.(as o jave told earlier. Thisis my major problem)

w_date = sy-datum.

w_date4(2) = w_date4(2) - 1.

WRITE: sy-datum, / w_date.

Regs,

ABAPer.