Working With Times

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I needed to know if there was a way to count the hours a user has been
logged on for. When they first log in, i record the time and when the
logoff i record the time, but now how would i subtract them.. specially if
they log on at 2300hr and log off at 1am in the morning..
thanks
 
The Subtract method of the DateTime structure should help you.

DateTime t1 = DateTime.Now;
DateTime t2 = DateTime.Now.AddHours(3);

TimeSpan t3 = t2.Subtract(t1);
 
I assume you are doing something along the lines of Session(“LoginTimeâ€) =
Now then the user logs in. When they log out you could do something along the
lines of:

Dim dt As DateTime = CType(Session("LoginTime"), DateTime)
Dim ts As TimeSpan = Now.Subtract(dt)

This would give you what you are looking for, I think. Have a look at the
help on TimeSpan.

Hope it helps.
Chris.
 
Thanks for the help

Chris Podmore said:
I assume you are doing something along the lines of Session(“LoginTimeâ€) =
Now then the user logs in. When they log out you could do something along the
lines of:

Dim dt As DateTime = CType(Session("LoginTime"), DateTime)
Dim ts As TimeSpan = Now.Subtract(dt)

This would give you what you are looking for, I think. Have a look at the
help on TimeSpan.

Hope it helps.
Chris.
 
Back
Top