Skip to Content
author's profile photo Former Member
Former Member

Difference between time stamps results in day or hours...

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Apr 11, 2008 at 02: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 11, 2008 at 01: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.