# question

## Calculate computer usage during time window

I need to calculate the number of minutes that customers have utilized a computer during the 2PM to 4PM time slot. Some of the customers have logged on outside of the window. How do I subtract those times from both the LogInDate and LogOutDate columns the Deleted Bookings Table? I figured out how to filter the window of time using the DATEPART [link text][1]function. [1]: /storage/temp/1560-library+login+logout+calculation.txt
1 comment

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
This site works from voting. You should indicate helpful answers by clicking on the thumbs up next to those answers. If any one answer lead to a solution you should indicate this by clicking on the check box next to that answer.
0 Likes 0 ·

·
If I understand you correctly, in the case when a customer logged on from 1pm until 5pm, you would want to return 2 hours for that customer as they were logged on for two hours between 2 and 4 (although 4 hours in total). I would use a case statement to determine the latest of (the time portion of LogInDate and 2pm ), and another to determine the earliest of (the time portion of LogOutDate and 4pm), then work out the datediff in mins between them. Note - be careful if customers can be logged in for >1 day, as you need to ensure you account for the date difference.
1 comment

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
Thanks Dave_Green. Perhaps a little more background information: Customers can log into a 30 minute, 60 minute or 120 minute computer and not use the full time, i.e. use 12 minutes on either of the 3 types of computers. If the customer logs in at 1202 and logs off at 1402, they would have used 2 minutes during the 2-4 time period window. They could use a 30 minute computer from 1549 to 1619 and use 11 minutes during that time period. I am relatively new at SQL. Would the Case statement look something like: CASE WHEN logindate <2 and logoutdate >4 THEN subtract logindate from logoutdate I could insert the results into a temporary table/table variable for later computation by month/year? Thanks for your help.
0 Likes 0 ·
1 comment

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
And you can group by the year and month should you wish to sum the DurationInWindow column, to get total activity in the period...
0 Likes 0 ·

You can open the Task Manager by right-clicking your computer clock and selecting "Start Task Manager.” When you click the “Performance” tab, you'll see a list of values in the window's System section. The “Up Time” value tells you how many days, hours, minutes and seconds the computer has been running.

Regards,

Will

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.