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 Module to obtain date

Former Member
0 Likes
971

Hi all

Can anyone suggest me the function module which satisfies below scenario:

Suppose i enter FROM date as :18.07.2006

and TO date as :20.07.2006

I should get number of days between these two dates as 1 and value :19.07.2006.

Thanks in advance

Regards

Neha Kapoor

9 REPLIES 9
Read only

Former Member
0 Likes
916

Hi,

Check this function modules

"SD_DATETIME_DIFFERENCE"

or

"HR_HK_DIFF_BT_2_DATES"

Thanks and Regards,

Bharat Kumar Reddy.V

Message was Added by: Bharat Reddy V

Read only

0 Likes
916

hi,

CHeck FM <b>DAYS_BETWEEN_TWO_DATES</b>

http://www.sap-basis-abap.com/sapab015.htm

Read only

Former Member
0 Likes
916

Hi Neha,

Use this FM

HR_E_NUM_OF_DAYS_OF_MONTH (To get no.of days of the month)

Reward points if helpful.

Regards,

Harini

Read only

Former Member
0 Likes
916

check this one .<b>CSCP_PARA1_GET_PERIODS</b> and Time uint is D.

Regards

Prabhu

Read only

Former Member
0 Likes
916

Hi Neha,

You can use <b>DAYS_BETWEEN_TWO_DATES</b> FM to get the days between 2 dates.


PARAMETER:p_date1 TYPE dats,
          p_date2 TYPE dats.

DATA:lv_diff TYPE i,
     lv_no_date type i.


CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
  EXPORTING
    i_datum_bis             = p_date1
    i_datum_von             = p_date2
  IMPORTING
    e_tage                  = lv_diff
  EXCEPTIONS
    days_method_not_defined = 1
    OTHERS                  = 2.
IF sy-subrc <> 0.
  WRITE:/ 'Error'.
ELSE.
  WRITE:/ lv_diff.
ENDIF.

if lv_diff < 0.
lv_diff = lv_diff * -1.
endif.

lv_no_date = lv_diff - 1.

<b>Reward if helpful</b>

Rgds,

Read only

Former Member
0 Likes
916

Hi neha,

1. just copy paste

2. It will list ALL THE DATES which fall in between,

and also the NUM OF DAYS.

3.

report abc.

PARAMETERS : FROMDATE TYPE SY-DATUM DEFAULT '20060701'.

PARAMETERS : TODATE TYPE SY-DATUM DEFAULT SY-DATUM.

perform mydays using fromdate todate.

*----


  • FORM

*----


FORM MYDAYS USING MYFROMDATE MYTODATE.

DATA : CURDATE TYPE SY-DATUM.

DATA : NUMOFDAYS TYPE I.

CURDATE = MYFROMDATE + 1.

DO.

IF CURDATE >= MYTODATE.

EXIT.

ENDIF.

NUMOFDAYS = NUMOFDAYS + 1.

WRITE 😕 CURDATE.

CURDATE = CURDATE + 1.

ENDDO.

WRITE 😕 '------- Num of days ' , numofdays .

ENDFORM. "MYDAYS

regards,

amit m.

Read only

Former Member
0 Likes
916

Hi,

declare the 2 dates that you have as DATS or type sy-datum. ( say d1 & d2 )

now declare a variable of type integer or NUMC. ( say n1 )

now n1 = d1 - d2...will give you the number of days between the 2 dates....

Read only

Former Member
0 Likes
916

Hi,

declare the 2 dates that you have as DATS or type sy-datum. ( say d1 & d2 )

now declare a variable of type integer or NUMC. ( say n1 )

now n1 = d1 - d2...will give you the number of days between the 2 dates....hence n1-1 should give u the difference between the two dates, also d1 + ( n1 - 1 ) should give the desired date.

Thanks & Regards

Saikiran

Read only

Former Member
0 Likes
916

hi all

try this for finding difference between two dates.

data : temp type i.

data : d1 type sy-datum,

d2 type sy-datum.

d1 = '20060720'.

d2 = '20060718'.

temp = d1 - d2.

write : / temp.