Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 08-06-2009
Member
 
Join Date: Mar 2009
Posts: 42
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???
Reply With Quote
  #2  
Old 08-06-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #3  
Old 08-06-2009
Member
 
Join Date: May 2008
Posts: 2,383
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
Reply With Quote
  #4  
Old 08-06-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search



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