473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Working With Times

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
--
Ad****@hotmail.com
Nov 19 '05 #1
3 1294
Vko
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);
"ACaunter" wrote:
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
--
Ad****@hotmail.com

Nov 19 '05 #2
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.

"ACaunter" wrote:
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
--
Ad****@hotmail.com

Nov 19 '05 #3
Thanks for the help

"Chris Podmore" wrote:
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.

"ACaunter" wrote:
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
--
Ad****@hotmail.com

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
ASP.NET 2.0 was working fine, then I installed XP SP2 an it stopped working. Unfortunately I do need SP2 so going back to SP1 is not an option. I am quite certain that it was working for a while...
8
by: shyamg | last post by:
plzzz help me............
1
by: plsHelpMe | last post by:
Hi All, I am facing an issue while testing my app for the cross browser compatibility. The scenario is as follows: I am having a component which is having a radio button against which i am...
1
by: robin1983 | last post by:
Dear All, I got stuck in simple problem, I have a two php file one for registration form and one for to check and insert into the table. The problem is that when I get any kind error in...
6
by: Mike Copeland | last post by:
I am working with a file of data that contains "time values" (e.g. "1225365563"), and I want to convert this data into something I can use in a program I'm developing. From what I've read about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.