TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   timespan in c#.net (http://forums.techarena.in/software-development/1193710.htm)

Ameyaa 08-06-2009 04:47 PM

timespan in c#.net
 
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 c#.net
 
Here is the solution of the code you required :

Code:

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 c#.net
 
I don't know about timespan but here is the solution you can do in VB.NET as follows :

Code:

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)
 
        MsgBox(ts)
    End Sub


MindSpace 08-06-2009 05:19 PM

Re: timespan in c#.net
 
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.


Code:

DateTime startTime = DateTime.Now;
Console.WriteLine(startTime);

Thread.Sleep(1700);

DateTime stopTime = DateTime.Now;
Console.WriteLine(stopTime);

TimeSpan duration = stopTime - startTime;
Console.WriteLine(duration);
               

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(hours.minute.second.mini-second)



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