My own Function-Module to calculate duration between 2 dates and 2 times
I was searching for a function module that should calculate the duration of 2 tasks .
Import Parameter:
DATE_FROM
DATE_TO
TIME_FROM
TIME_TO
As result I need values separated into
YEARS
MONTHS
DAYS
HOURS
MINUTES
SECONDS
Most standard function deliver only one(1) result and than this return value is from type F (floating number, like 2,34546787E-03) and I did not want to convert the result into integer. Other standard functions look like they could work, but when I checked them I found that they where calculation wrong!
So I came to the conclusion to copy+paste what ever I can and I wrote my own function module using the SAP function module ‘L_TO_TIME_DIFF’
Here it is (check attachment)
Please comment if you find a BUG, I will try to solve it.
Germany, 16.01.2016
Jörg Sauterleute
—-
UPDATE, 17.01.2016
I found and error and replaced attachment/coding…
UPDATE, 22.01.2016
another bug found (seconds where wrong when time_to < time_from)
UPDATE, 28.01.2016
next bug with time (seconds where wrong, when date_to = date_from AND time_to < time_from) 😛
Hi,
We do not have function L_TO_TIME_DIFF on our newer system .
We do have it on the older one.....
puzzling....
Regards.
I only know further function modules (like COPF_DETERMINE_DURATION) which are using "floating" return values.
You can use them instead L_TO_TIME_DIFF, but than you must convert the floating value (TYPE f) into integer (TYPE int4).
regards
btw. please recognize that I have replaced my coding (minor bugs!)