TechArena Community

TechArena Community (
-   Software Development (
-   -   timespan in (

Ameyaa 08-06-2009 04:47 PM

timespan in
I am working in a small company where all the people are working on the computer. Now i am trying to build application on Time Attendance System. I am building this application to see when the people are getting in the office & when going out of the office also it should calculate the time they were working. Mean Login Time subtracted by Logout Time. can anyone help me with this???

Reegan 08-06-2009 05:01 PM

Re: timespan in
Here is the solution of the code you required :


dim diff as TimeSpan

diff = DateTime.Now - DateTime.Today

Here i have just subtracted both the login time & logout time. If any help required post it again with the query.

opaper 08-06-2009 05:08 PM

Re: timespan in
I don't know about timespan but here is the solution you can do in VB.NET as follows :


Private Sub
Button1_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Button1.Click
        Dim dtStart, dtEnd, ts
        dtStart = DateTime.Parse(StartTime.Text)
        dtEnd = DateTime.Parse(EndTime.Text)
        'ts = DateDiff("n", dtStart, dtEnd) ' in case you need it in minutes
        ts = DateDiff("h", dtStart, dtEnd)
    End Sub

MindSpace 08-06-2009 05:19 PM

Re: timespan in
In C #, there is its own class, stores the information over one time interval. The name of the class is time, and are into the system namespace.

The time of class is much easy one to use. If we have a class example time, we are in a position to directly assigning to it a difference of two DateTime example. To see the code here under in order seeing like making.


DateTime startTime = DateTime.Now;


DateTime stopTime = DateTime.Now;

TimeSpan duration = stopTime - startTime;

The output of this code looks something like this:

Login : Date(month/day/year) Time(hours:minute:second)
Logout : Date(month/day/year) Time(hours:minute:second)
Difference : Time(

All times are GMT +5.5. The time now is 05:58 AM.