04-11-2008 2:35 PM
Hello Gurus,
Is there any function module to find the differences between two time stamps and return results in the form of hours or days.
Thanks,
Feroz.
04-11-2008 3:02 PM
Try Out below FMs
Some of these FMs are giving difference in seconds then
just devide it by 60 to get minute value
devide it by 3600 to get hour value
HR_TIME_AND_DURATION
SD_CALC_DURATION_FROM_DATETIME
CCU_TIMESTAMP_DIFFERENCE
SD_DATETIME_DIFFERENCE
HR_PDC_CALCULATE_TIME_DIFF
TIMECALC_DIFF
SCSM_TIME_DIFF_GET
SCOV_TIME_DIFF
SRET_TIME_DIFF_GET
FM L_MC_TIME_DIFFERENCE, this gives time difference with the unit.
eg : time1 = 12:30:00
time2 = 13:10:00 .
difference is 40min .
============
for converting seconds to minutes hours nd days..
DATA: SECS TYPE I,
HOURS_OUT TYPE I.
PARAMETERS P_STRDTE LIKE SY-DATUM.
CALL FUNCTION 'SWI_DURATION_DETERMINE'
EXPORTING
START_DATE = P_STRDTE
END_DATE = SY-DATUM
START_TIME = SY-UZEIT
END_TIME = SY-UZEIT
IMPORTING
DURATION = SECS.
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
EXPORTING
INPUT = SECS
ROUND_SIGN = ' '
UNIT_IN = 'S'
UNIT_OUT = 'H'
IMPORTING
OUTPUT = HOURS_OUT
EXCEPTIONS
CONVERSION_NOT_FOUND = 1
DIVISION_BY_ZERO = 2
INPUT_INVALID = 3
OUTPUT_INVALID = 4
OVERFLOW = 5
TYPE_INVALID = 6
UNITS_MISSING = 7
UNIT_IN_NOT_FOUND = 8
UNIT_OUT_NOT_FOUND = 9
OTHERS = 10.
IF SY-SUBRC EQ 0.
WRITE:/ HOURS_OUT, 'HOURS HAVE PASSED SINCE', P_STRDTE.
ELSE.
WRITE:/ 'ERROR IN FUNCTION'.
ENDIF.
and if you wanna have days also ...
If you want to convert some number of seconds into the number of days, hours, minutes and seconds
REPORT ztest LINE-SIZE 250.
DATA: seconds TYPE i VALUE 180001,
days TYPE i,
dur_ti LIKE sy-uzeit.
days = seconds DIV 86400. "Seconds per day
seconds = seconds MOD 86400.
dur_ti = seconds.
WRITE : /001 days, dur_ti.
Hope it will solve your problem
<REMOVED BY MODERATOR>
Thanks & Regards
ilesh 24x7
Edited by: Alvaro Tejada Galindo on Apr 11, 2008 12:21 PM
04-11-2008 2:52 PM
Refer to this Function Module CCU_TIMESTAMP_DIFFERENCE.
This will return number of seconds between two time stamps. You can use your own logic to find number of days, hours from number of seconds.
Regards,
Ramesh
04-11-2008 3:02 PM
Try Out below FMs
Some of these FMs are giving difference in seconds then
just devide it by 60 to get minute value
devide it by 3600 to get hour value
HR_TIME_AND_DURATION
SD_CALC_DURATION_FROM_DATETIME
CCU_TIMESTAMP_DIFFERENCE
SD_DATETIME_DIFFERENCE
HR_PDC_CALCULATE_TIME_DIFF
TIMECALC_DIFF
SCSM_TIME_DIFF_GET
SCOV_TIME_DIFF
SRET_TIME_DIFF_GET
FM L_MC_TIME_DIFFERENCE, this gives time difference with the unit.
eg : time1 = 12:30:00
time2 = 13:10:00 .
difference is 40min .
============
for converting seconds to minutes hours nd days..
DATA: SECS TYPE I,
HOURS_OUT TYPE I.
PARAMETERS P_STRDTE LIKE SY-DATUM.
CALL FUNCTION 'SWI_DURATION_DETERMINE'
EXPORTING
START_DATE = P_STRDTE
END_DATE = SY-DATUM
START_TIME = SY-UZEIT
END_TIME = SY-UZEIT
IMPORTING
DURATION = SECS.
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
EXPORTING
INPUT = SECS
ROUND_SIGN = ' '
UNIT_IN = 'S'
UNIT_OUT = 'H'
IMPORTING
OUTPUT = HOURS_OUT
EXCEPTIONS
CONVERSION_NOT_FOUND = 1
DIVISION_BY_ZERO = 2
INPUT_INVALID = 3
OUTPUT_INVALID = 4
OVERFLOW = 5
TYPE_INVALID = 6
UNITS_MISSING = 7
UNIT_IN_NOT_FOUND = 8
UNIT_OUT_NOT_FOUND = 9
OTHERS = 10.
IF SY-SUBRC EQ 0.
WRITE:/ HOURS_OUT, 'HOURS HAVE PASSED SINCE', P_STRDTE.
ELSE.
WRITE:/ 'ERROR IN FUNCTION'.
ENDIF.
and if you wanna have days also ...
If you want to convert some number of seconds into the number of days, hours, minutes and seconds
REPORT ztest LINE-SIZE 250.
DATA: seconds TYPE i VALUE 180001,
days TYPE i,
dur_ti LIKE sy-uzeit.
days = seconds DIV 86400. "Seconds per day
seconds = seconds MOD 86400.
dur_ti = seconds.
WRITE : /001 days, dur_ti.
Hope it will solve your problem
<REMOVED BY MODERATOR>
Thanks & Regards
ilesh 24x7
Edited by: Alvaro Tejada Galindo on Apr 11, 2008 12:21 PM