I have an MSSQL query that runs order productivity for a time period. Basically it calculates how long an order takes from start date to completion date in minutes.
What I am doing is getting the date and timestamp where the order is created(a) and getting the date and time stamp where the order is completed(b) and subtracting them then multiplying them by 1440 to get the minutes between the 2 dates.
,FLOOR(((CAST(b.[AuditInsertTimestamp2] AS FLOAT)) - (CAST(a.[AuditInsertTimestamp2] AS FLOAT))) * 1440) AS [Minutes]
This works perfectly fine but this also counts the time that our business is closed. What I want to do is just return how much time between these dates is taken while our business is open (6:30AM – 5:00PM). The dates can span multiple days or just a single day. Any ideas?!?!?!
Thanks!!!!
Here is the final queries if anyone cares to know….
In my Main query I have a case statment that if its less than a day between @StartDate and @Enddate it just subtracts the time otherwise if its more than a day or if its less than a day but its less than 24 hours it sends it to this funtction. Everything seems to work Perfect!!!