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

Time Difference between the fields

nivaskumar2
Explorer
0 Likes
1,811

Dear Gurus,

I have two date fields from_date and to_date .I have to time fields from_time and to_time.I need to calculate the difference in hours between (from_date,from time ) and (To_date,to_time) in hours.

I have used various function modules to get the difference.i used GET_DELTA_TIME_FROM_DT it worked but it will convert the output to zero if the hours exceeds 240000 hrs.

Could you Please help to get my requirement.As this stopping my work

1 ACCEPTED SOLUTION
Read only

nivaskumar2
Explorer
0 Likes
1,549

Thanks,The threads helped to solve my requirement.But unfortunately the requirement has changed slightly by changed.Now they days and hours format.

ex : 5 days 15 hrs 16mins 2 secs

Please Help me.This needs to be finished my tomorrow.

10 REPLIES 10
Read only

Former Member
0 Likes
1,549

SD_CALC_DURATION_FROM_DATETIME: Find the difference between two date/time and report the difference in hours

Check whether this cud help you.

Read only

Former Member
0 Likes
1,549

Use FM SD_DATETIME_DIFFERENCE u2013 Difference in days and time for two dates

Read only

Former Member
0 Likes
1,549

Use FM /SDF/CMO_DATETIME_DIFFERENCE and convert into hrs.

Read only

faisalatsap
Active Contributor
0 Likes
1,549

Hi,

Test the following Sample Code hope will solve out your problem,

data: t1 TYPE t,
      t2 TYPE t,
      def TYPE p.

t1 = '080808'.
t2 = '090909'.

BREAK-POINT.
CALL FUNCTION 'SD_DATETIME_DIFFERENCE'
  EXPORTING
    date1                  = '20090101'
    time1                  = t1
    date2                  = '20090101'
    time2                  = t2
 IMPORTING
*   DATEDIFF               =
   TIMEDIFF               = def
*   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.


WRITE: / t1, / t2, / def.

Kind Regards,

Faisal

Read only

Former Member
0 Likes
1,549

Hi,

try these function modules

SD_CALC_DURATION_FROM_DATETIME

SD_DATETIME_DIFFERENCE

Regards,

Jyothi CH.

Read only

Former Member
0 Likes
1,549

TRY

fm : ISHMED_CALC_DATE_TIME_DIFF

Regards

Shashi

Read only

nivaskumar2
Explorer
0 Likes
1,550

Thanks,The threads helped to solve my requirement.But unfortunately the requirement has changed slightly by changed.Now they days and hours format.

ex : 5 days 15 hrs 16mins 2 secs

Please Help me.This needs to be finished my tomorrow.

Read only

0 Likes
1,549

Put on your spider man dress and there you go!

Read only

Former Member
0 Likes
1,549

Check this:

DATA: from_date TYPE d,
      to_date TYPE d,
      diff_date TYPE p DECIMALS 2,
      from_time TYPE t,
      to_time TYPE t,
      diff_time TYPE p DECIMALS 2.
from_date = sy-datum - 5.
to_date = sy-datum.
from_time = 120000.
to_time = 115555.
CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
  EXPORTING
    date1                  = from_date
    time1                  = from_time
    date2                  = to_date
    time2                  = to_time
 IMPORTING
   datediff               = diff_date
   timediff               = diff_time.
WRITE: diff_date, diff_time.

Read only

nivaskumar2
Explorer
0 Likes
1,549

Hi Friends,

Your suggestions and recomendations has helped me solve my requirement. Thank you all for your support.

.