Results 1 to 4 of 4

Thread: timespan in c#.net

  1. #1
    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???

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    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

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    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)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,691,529.51673 seconds with 15 queries