I have these fields in my T-SQL database – startTime and endTime and processTime.
The process time is the amount of time from start to end time.
So, one startTime example is 22:50:59 and its endTime is 23:14:23.
Process time would be .39 (The current code):
SELECT convert( decimal(18,0), totalItems
/(datediff(ss,sessionStartTime,sessionEndTime)/60.00/60.00) )
AS processTime
This seems to be working for the most part, but it doesn’t work when the startTime and endTime span across a day – for example, a startTime is 23:17:27 and an endTime of 00:31:23.
In other words, they started at 10:17 p.m., and finished at about 12:31 a.m. the following morning, but SQL isn’t seeing this, because the processTime is displaying as a negative number (-22.77)…
How do I convert these negative times into positive times?
I do have separate date fields – a startDate, and an endDate.
I’m assuming you’re including dates…(?)
Here is a sample I ran — seems to work as expected:
Here’s the results:
One thing you might do is re-check the scope of your decimal conversion. E.g.: this produces a different results, depending on where you put the parens before the division:
Here are the results of that: