Sleep is good. Coffee is better.
Let's say your audit table looks like
UserName DateIn DateOut
-------- ------------------- -------------------
Jim 2012-03-27 11:30:23 2012-03-27 11:45:19
Jim 2012-03-29 08:15:12
And the current date is today. The reason that record two has no value for DateOut could be one of
- The network failed
- The server died
- The user kicked out the power cord on his computer
Or several other reasons. In any case, when Jim goes to log back in he will end up with the following
UserName DateIn DateOut
-------- ------------------- -------------------
Jim 2012-03-27 11:30:23 2012-03-27 11:45:19
Jim 2012-03-29 08:15:12
Jim 2012-04-01 13:24:17
This is not good because it looks like Jim has logged in twice without logging out. Come to think of it, if it is possible for a user to log in on two different machines at the same time then you might add a machine name field to the audit table (a good idea in any case). Let's keep it simple for now. When the app starts you will have to check for unclosed logins and put some value in to "close" them. Let's assume that has been done and the audit table now looks like
UserName DateIn DateOut
-------- ------------------- -------------------
Jim 2012-03-27 11:30:23 2012-03-27 11:45:19
Jim 2012-03-29 08:15:12 2012-03-29 24:00:00
Jim 2012-04-01 13:24:17
If you were to use the query
UPDATE AuditTrail SET DateTimeOut = now() where Username ='Jim'
You would end up with
UserName DateIn DateOut
-------- ------------------- -------------------
Jim 2012-03-27 …