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

function for dates

Former Member
0 Likes
992

Hi Experts!

i want to calculate months b/w 2 dates , is there function for this . can i find days and year also .plz tell me .

thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
948

Hi,

please take the help from the code as below :

data : date1 type sy-datum,

date2 type sy-datum.

data : w_day(3),

nw_day(3).

date1 = '20070701'.

date2 = '20070731'.

data : days type VTBBEWE-ATAGE, years type VTBBEWE-ATAGE, months type VTBBEWE-ATAGE.

data : a_new type sy-datum, b_new type sy-datum.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

EXPORTING

i_date_from = date1

I_KEY_DAY_FROM = '00'

i_date_to = date2

I_KEY_DAY_TO = '00'

I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = days

E_MONTHS = months

E_YEARS = years.

Regards,

Sandeep Kaushik

8 REPLIES 8
Read only

Former Member
0 Likes
948

you can try

FIMA_DAYS_AND_MONTHS_AND_YEARS

or

FIMA_DECIMAL_MONTHS_AND_YEARS

regards

shiba dutta

Read only

Former Member
0 Likes
948

hi

good

try these functioin modules

HR_IE_NUM_PRSI_WEEKS Return the number of weeks between two dates.

thanks

mrutyun^

Read only

Former Member
0 Likes
948

Hi ,

There is no FM which will return the difference in Months, but days months and year.

Belwo is the FM:

HR_HK_DIFF_BT_2_DATES Days, months and years between two dates

Revert back if any issues,

Reward if helpful.

Regards,

Naveen

Read only

Former Member
0 Likes
949

Hi,

please take the help from the code as below :

data : date1 type sy-datum,

date2 type sy-datum.

data : w_day(3),

nw_day(3).

date1 = '20070701'.

date2 = '20070731'.

data : days type VTBBEWE-ATAGE, years type VTBBEWE-ATAGE, months type VTBBEWE-ATAGE.

data : a_new type sy-datum, b_new type sy-datum.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

EXPORTING

i_date_from = date1

I_KEY_DAY_FROM = '00'

i_date_to = date2

I_KEY_DAY_TO = '00'

I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = days

E_MONTHS = months

E_YEARS = years.

Regards,

Sandeep Kaushik

Read only

varma_narayana
Active Contributor
0 Likes
948

Hi...

Check the following code for subtract years/months/date from particular date:

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 <b>'FIMA_DAYS_AND_MONTHS_AND_YEARS'</b>

exporting

i_date_from = FROMDATE

i_date_to = TODATE

  • I_FLG_SEPARATE = ' '

IMPORTING

E_DAYS = EDAYS

E_MONTHS = EMONTHS

E_YEARS = EYEARS.

WRITE:/ 'Difference in Days ', EDAYS.

WRITE:/ 'Difference in Months ', EMONTHS.

WRITE:/ 'Difference in Years ', EYEARS.

INITIALIZATION.

FROMDATE = SY-DATUM - 60.

<b>reward if Helpful.</b>

Read only

Former Member
0 Likes
948

HAI TRY THIS

REPORT ZSAN_SDN2.

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME.

PARAMETER:

N1 TYPE T,

N2 TYPE T.

DATA: DN1 TYPE T,

DN2 TYPE T,

DN3 TYPE I,

DN4 TYPE I,

DN6 TYPE I,

DN5 TYPE I.

SELECTION-SCREEN:

BEGIN OF LINE,

PUSHBUTTON 2(10) BUT1 USER-COMMAND CALC,

PUSHBUTTON 13(10) BUT2 USER-COMMAND EXIT,

END OF LINE.

SELECTION-SCREEN END OF BLOCK B1.

AT SELECTION-SCREEN.

CASE SY-UCOMM.

WHEN 'CALC'.

MOVE: N1 TO DN1,

N2 TO DN2.

DN3 = DN2 - DN1 .

DN3 = DN3 MOD 86400.

DN4 = DN3 / 3600 .

DN6 = DN3 / 60 .

DN5 = DN6 MOD 60.

DN3 = DN3 MOD 3600 .

DN3 = DN3 MOD 60 .

LEAVE TO LIST-PROCESSING.

SET PF-STATUS SPACE.

WRITE: / DN4, 'hours'.

WRITE: / DN5, 'minutes'.

WRITE: / DN3, 'seconds'.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

INITIALIZATION.

BUT1 = 'calc'.

BUT2 = 'exit'.

Read only

0 Likes
948

SORRY.. ITS FOR TIME

Read only

Former Member
0 Likes
948

hi,

The appropriate finction module is '<u><b> HR_SGPBS_YRS_MTHS_DAYS'.</b></u>

<i><b>regards

Debjani Lahiri

Rewards point for helpful answer</b></i>