If you want to do this within a program:
Just create a simple array containing class User type variable.
User class should have attributes: userId, loginTime, logoutTime.
Checking the total number of users who logged in and logged out in a given time range will be something like:
for (user in userArray) if (user.loginTime > inputLoginTime && user.logoutTime < inputLogoutTime) count++;
You can check for the total number of users in O(n) time.
If you want to do it in Server, eg. MySQL.
Create a table User with userId, loginTime, logoutTime as column.
SELECT COUNT(*) FROM User WHERE User.loginTime > inputLoginTime AND User.logoutTime < inputLogoutTime;
loginTimeand a copy of the data sorted bylogoutTime. To compute the users that logged in between A and B and logged out between C and D, first compute users S that logged in between A and B and then users T that logged out between C and D. Return the intersection of S and T.