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

Calculate between 2 dates and time

Former Member
0 Likes
967

Dear all

I have to Timestamps (Date and Time) and should calculate the minutes inbetween.

For ex:

IN = 25.07.2011 09:01:20

OUT = 26.07.2011 10:15:30

How Can I calculate the difference between this 2 dates and times? If Possible also with considering the factory calendar.

Is there a FM?

thank you

Herbert

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
899

Hi Herbert,

I've used FM DELTA_TIME_DAY_HOUR in the past. It imports a beginning date and time and an ending date and time and exports the minutes between them.

Brenda

Dear all

I have to Timestamps (Date and Time) and should calculate the minutes inbetween.

For ex:

IN = 25.07.2011 09:01:20

OUT = 26.07.2011 10:15:30

How Can I calculate the difference between this 2 dates and times? If Possible also with considering the factory calendar.

Is there a FM?

thank you

Herbert

4 REPLIES 4
Read only

Former Member
0 Likes
899

Hi

please use below FM '/SDF/CMO_DATETIME_DIFFERENCE' to calculate time date between two timestamp.

Regards

Rohit

Read only

former_member209703
Active Contributor
0 Likes
899

There are several, you can try this IGN_TIMESTAMP_DIFFERENCE

Read only

Former Member
0 Likes
900

Hi Herbert,

I've used FM DELTA_TIME_DAY_HOUR in the past. It imports a beginning date and time and an ending date and time and exports the minutes between them.

Brenda

Read only

Sandra_Rossi
Active Contributor
0 Likes
899

Hi Herbert,

the official API (ABAP documentation) to calculate the difference between 2 time stamps is the class CL_ABAP_TSTMP, method SUBTRACT. It calculates a number of seconds.But it doesn't take into account a factory calendar.

So

you'd have to calculate the number of working days using the official DATE_CONVERT_TO_FACTORYDATE function module to convert both dates into day counters, subtract them. For getting the minutes at the lower and upper dates, I think you only need to subtract the time part of each time stamp. One question to ask is what happens if one or both of these 2 dates is not a working day.

So, for your example:

IN = 25.07.2011 09:01:20

OUT = 29.07.2011 10:15:30 (here I added 3 days to your example)

How many minutes between 26.07 and 28.07 : 4320 (3 days * 1440 minutes per day)

How many minutes at IN date : 899 (( 24:00:00 - 09:01:20 ) / 60)

How many minutes at OUT date : 616 (10:15:30 / 60)

PS: Converting a time into seconds is done using implicit type conversion (integer_number_of_seconds = time), and subtracting 2 time data objects returns a number of seconds.

Best regards

Sandra