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

Calculating difference between two timestamps considering working hours

Former Member
0 Likes
1,397

Hi guys,

I am looking for a standard function module for the following task:

I need to calculate the time difference between two timestamps. So far so easy.

The problem is, that I need to take working hours into account. So instead of just calculating the time difference I need the time difference in working hours.

Say working hours are from 9 to 5 and the first timestamp would be 10 am today and the second would be 10 am tomorrow, than the result I am looking for is not 24 hours but instead 8 hours, which would be the total of working hours between those two timestamps.

Any hints are very much appreciated.

Many thanks in advance,

Tobias

Hi guys,

I am looking for a standard function module for the following task:

I need to calculate the time difference between two timestamps. So far so easy.

The problem is, that I need to take working hours into account. So instead of just calculating the time difference I need the time difference in working hours.

Say working hours are from 9 to 5 and the first timestamp would be 10 am today and the second would be 10 am tomorrow, than the result I am looking for is not 24 hours but instead 8 hours, which would be the total of working hours between those two timestamps.

Any hints are very much appreciated.

Many thanks in advance,

Tobias

2 REPLIES 2
Read only

FredericGirod
Active Contributor
0 Likes
700

Hi,

maybe just calculate the number of working day with the function  ...convert...to...factorydate ..    and just add the number of hour at the first day and the last day ..   no ?

regards

Fred

Read only

Former Member
0 Likes
700

Hi Tobias,

I don't have a code sample, but I guess the logic would be:

1. Check the dates between the start & end date of the timestamps:

1.a.  If it's the same date (and your certain that the ending time stamp is within the working hours...):

    Get the time difference. => the solution to your problem.

else continue with 2.

2..  If the dates are different (and end date > start date)

2.a. Get the time from starting timestamp till end of working day.

2.b. Get the no. of complete working days between the start & end.

       You can this FM to accomplish this: RKE_SELECT_FACTDAYS_FOR_PERIOD

2.c. Get the time between start of working day till the ending time stamp.

=> The sum of 2.a, 2.b and 2.c is the solution to your problem.

Have fun!