
Hi there,
how to get exact time difference in seconds,
I am getting once second difference when i am subtracting (endtime - starttime) - breaktime
below is the sample code i am using
static void TimeMinusMinutes(Args _args)
{
str start,end;
real startTime,endTime,totalTime,lunch,totalTimeExcudingLunch,Hours;
start = "8:00:00 am";
end = "5:00:00 pm";
startTime = str2time(start);
endTime = str2time(end);
if (startTime > endTime)
{
totalTime = endTime + (str2time('23:59:59') - startTime);
}
else
{
totalTime = endTime - startTime;
}
lunch = 1 * 60;
totalTimeExcudingLunch = (totalTime - lunch)/3600;
info(strFmt('%1', totalTimeExcudingLunch));
}
i am getting the output 8.98 instead of 8.99
Can you please guide me how can i achieve above requirement
*This post is locked for comments
I have the same question (0)Why do you say that it should be 8.99? As far as I can say, 32340/3600 is 8.9833333... If you want to round up, you can, of course.
By the way, did you really mean that lunch is one minute? Didn't you mean one hour?
An alternative design would be creating two DateTime values and subtracting them. You would get a DateSpan object, which has properties like TotalSeconds and TotalHours.