2012 Oct 13 7:00 AM
Hi,
How to calculate the difference between two dates in abap ,
in which one is the current day date calculated by sy-datum and the data type of other date is DATS ?
2012 Oct 13 10:24 AM
Hi Somya,
you can utilize the function like SD_DATETIME_DIFFERENCE for the same.
Thanks & Regards,
Jayraj Joshi
2012 Oct 13 10:44 AM
Hello Somya,
No issues my friend. It will work fine, just take 2 variables assign one to sy-datum and another to dats. You will get the result.
Is there any other problem you are facing, please let know .
Thanks & Regards,
Varun Kumar Sahu
2012 Oct 13 11:01 AM
Did you try SUBTRACT or "-" operator (between two date field it will give an integer): number of days ?
(Actually look for conversion of data type (*), as the operator require numeric data, it will convert date to numeric, and as you can read a date is converted to the number of day since 01.01.0001, and vice-versa)
Regards,
Raymond
2012 Oct 13 11:47 AM
Hi,
you can directly use - operator, after using conversion routine.
Regards,
Prakash.
2012 Oct 14 6:57 PM
Data type of sy-datum is DATS. So, there should be no issue in addition & subtraction in your 2 variables.
Please correct me if I am wrong.
Thanks,
2012 Oct 15 7:49 AM
Hi,
Use the function module " HR_HK_DIFF_BT_2_DATE".
Here is the implementation:
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
date1 = sy-datum
date2 = date2
output_format = '02'
IMPORTING
* YEARS =
* MONTHS =
days = var_date " store no of days in between dates+1
EXCEPTIONS
invalid_dates_specified = 1
OTHERS = 2
.
var_date = (var_date -1)"store no of days in between dates
Regards,
Priyanka
2012 Oct 15 8:07 AM
Hi,
Both sy-datum and dats have same technical attributes when you compared with domain.
Calculations with dates values are possible.
Example:
2012 Oct 15 8:52 AM
Here is the sample code just copy it and analyze i hope u can understand .
PARAMETERS: p_date1 TYPE sy-datum,
p_date2 TYPE sy-datum.
DATA: w_a TYPE i,
w_b TYPE i,
w_c TYPE i.
IF p_date1 > p_date2.
w_a = p_date1 - p_date2.
w_b = w_a / 7.
w_c = w_a mod 7.
WRITE: 'total',w_a,'days', 'OR ', w_b,'weeks',w_c,'days' .
ENDIF.
Regards
Mahesh
2012 Oct 15 9:48 AM
Hi Sowmya,
Check this below Program.
I think it wil satisfy ur requirement.
PARAMETERS : p_month TYPE sy-datum,
p_year TYPE dats.
data: i_date type p.
CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
EXPORTING
DATE1 = p_month
* TIME1 =
DATE2 = p_year
* TIME2 =
IMPORTING
DATEDIFF = i_date
* TIMEDIFF =
* EARLIEST =
EXCEPTIONS
INVALID_DATETIME = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
in the variable i_date will give you the exact output.