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

Date Time Calculation

Former Member
0 Likes
1,018

Hi all,

I 'm wondering if there is any function or form available for counting time used between 2 point of time.

I did a little research and if the 2 point of time are in the same day, i can simply deducted them using variable with type sy-uzeit.

but since these 2 point of time, are on 2 different date, i'm having difficulty on calculating time difference between them.

ex : if i wanna calculate from 2008/04/12 (yyyy/mm/dd) 20:00 (hh:mm) to 2008/04/16 11:00 and i want the result to be displayed in hh:mm.

should i use 2 variable type sy-datum, and sy-uzeit for counting them? or is there any easier way around it?

<REMOVED BY MODERATOR>

tks and rgds,

William Prawira

Edited by: Alvaro Tejada Galindo on Apr 16, 2008 12:47 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
963

Hi William,

You can try using the Function Module CCU_TIMESTAMP_DIFFERENCE by giving the date and time.

sample code:

parameters : u_limit type CCUPEAKA-TIMESTAMP,

l_limit type CCUPEAKA-TIMESTAMP.

data : diff type i.

start-of-selection.

CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'

EXPORTING

TIMESTAMP1 = u_limit

TIMESTAMP2 = l_limit

  • IMPORTING

DIFFERENCE = diff.

Output:

If we pass

u_limit - 20080416102715

l_limit - 20080416100715

Diff = 1200

If you divide Diff by 60 you get the minutes and divide this Diff appropriately to get hours and milliseconds.

Thanks,

A.Melchizedek

6 REPLIES 6
Read only

Former Member
0 Likes
963

Hi,

Please use the FM SD_DATETIME_DIFFERENCE.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
963

thanks for the fast reply.

will try soon <REMOVED BY MODERATOR>

thanks

Edited by: Alvaro Tejada Galindo on Apr 16, 2008 12:48 PM

Read only

Former Member
0 Likes
963

You can directly use a int variable to hold the difference.


data: v_date_diff type i,
        v_time_diff type i.

v_date_diff = date2 - date1.
v_time_diff = time2 - time1. " Gives difference in seconds
v_time_diff = v_time_diff / 60. " Gives difference in Minutes 

Read only

Former Member
0 Likes
964

Hi William,

You can try using the Function Module CCU_TIMESTAMP_DIFFERENCE by giving the date and time.

sample code:

parameters : u_limit type CCUPEAKA-TIMESTAMP,

l_limit type CCUPEAKA-TIMESTAMP.

data : diff type i.

start-of-selection.

CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'

EXPORTING

TIMESTAMP1 = u_limit

TIMESTAMP2 = l_limit

  • IMPORTING

DIFFERENCE = diff.

Output:

If we pass

u_limit - 20080416102715

l_limit - 20080416100715

Diff = 1200

If you divide Diff by 60 you get the minutes and divide this Diff appropriately to get hours and milliseconds.

Thanks,

A.Melchizedek

Read only

Former Member
0 Likes
963

Hi,

Please check this function module as it takes two dates and two times and returns the difference of those.

'/SDF/CMO_DATETIME_DIFFERENCE'

Reward points if helpful.

Thanks and Regards.

Read only

Former Member
0 Likes
963

thanks for all the answers.

problem solved