Hi All,
I have an urgent requirement to calculate days,hours,minutes and seconds between first creation order (date and time), and confirmed creation order (Date and time.)
E.g Begin Date 02.01.2008 Begin Time 11:12:23
End Date 08.01.2008 End Time 12:12:28
Now i have to find days,hours,minutes and seconds between The Begin Data(date and Time)
and End Data(date and Time).
Please let me know if there is any FM which could help me or any other way to solve this issue.
All helpful ans will be immediately rewarded
Thanks
Vijay
Hi,
you can use the FM SALP_SM_CALC_TIME_DIFFERENCE to get the difference in seconds.
To calculate the days, hours, etc you can use the DIV and MOD function like this:
days = seconds DIV 86400.
rest = seconds MOD 86400.
hours = rest DIV 3600.
rest = rest MOD 3600.
minutes = rest DIV 60.
seconds = rest mod 60.
Kindly Regards,
Stefan
Hi Vijay, u can do like this.
Create a calculates keyfigure as mentioned below.
from calculated keyfigure screen
create two variables, one for start date and other for end date.
and calculate the difference between these dates.
Now you will get difference between days.
And to calculate the difference in working days, u can use the below code.
Use function Module : HOLIDAY_GET to get holidays between two provided dates and provided calender.
In update rules, create 2 variables(l_date1, l_date2) of type SY-Datum and one for date_diff type N.
Date_diff = l_date1 - l_date2 -(no. of holidays).
kindly reward if found helpful.
cheers,
Hema.
Hi Vijay, also try this, this will solve ur problem. I guess.
use function module : it works,
HR_HK_DIFF_BT_2_DATES
give output format = 03 and get the value in days.
code is as below :
data : DATE1 type P0001-BEGDA,
DATE2 type P0001-BEGDA,
YEARS type P0347-SCRYY,
MONTHS type P0347-SCRMM,
DAYS type P0347-SCRDD.
date1 = '20070331'.
date2 = '20070101'.
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
DATE1 = date1
DATE2 = date2
OUTPUT_FORMAT = '03'
IMPORTING
YEARS = years
MONTHS = months
DAYS = days
EXCEPTIONS
INVALID_DATES_SPECIFIED = 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 : days.
cheers,
Hema.
Hi,
%DIFF(op1:op2:MSECONDS|SECONDS|MINUTES|HOURS|DAYS|MONTHS|*YEARS)
%DIFF(op1:op2:MS|S|MN|H|D|M|*Y)%DIFF produces the difference (duration) between two date or time values. The first and second parameters must have the same, or compatible types. The following combinations are possible:
Date and date
Time and time
Timestamp and timestamp
Date and timestamp (only the date portion of the timestamp is considered)
Time and timestamp (only the time portion of the timestamp is considered).
The third parameter specifies the unit. The following units are valid:
For two dates or a date and a timestamp: *DAYS, *MONTHS, and *YEARS
For two times or a time and a timestamp: *SECONDS, *MINUTES, and *HOURS
For two timestamps: *MSECONDS, *SECONDS, *MINUTES, *HOURS, *DAYS, *MONTHS, and *YEARS
The difference is calculated by subtracting the second operand from the first.
The result is rounded down, with any remainder discarded. For example, 61 minutes is equal to 1 hour, and 59 minutes is equal to 0 hours.
The value returned by the function is compatible with both type numeric and type duration. You can add the result to a number (type numeric) or a date, time, or timestamp (type duration).
If you ask for the difference in microseconds between two timestamps that are more than 32 years 9 months apart, you will exceed the 15-digit limit for duration values. This will result in an error or truncation.
For more information, see Date Operations or Built-in Functions
regards,
vasavi.
reward if helpful
Add a comment