Dipak Akhade Dipak Akhade - 1 month ago 7
C# Question

Operation on server time using c#

I have table in MySQL as shown below. You can see I have inTime and outTime columns and where you found inTime by default outTime will be 00:00:00 and vice versa. I want to calculate total_inTime for a any single date in such a way that addition of all differences between intime and outTime. (first_outTime-first_inTime like this).

enter image description here

How can I calculate total_inTime from this and how to do operations on inTime and outTime which is in HH:mm:ss format in c#?


Try this Example:

DateTime inTime = Convert.ToDateTime("17:19:44"); //example inTime
DateTime outTime = Convert.ToDateTime("19:19:00"); //example outTime
TimeSpan span = outTime - inTime;
TimeSpan duration = span.Duration();



For performing the operation on your Table, do something like this:

MySqlDataReader mydr = cmd.ExecuteReader();
while (mydr.Read())
    DateTime inTime = Convert.ToDateTime(mydr["inTime"]);
    DateTime outTime = Convert.ToDateTime(mydr["outTime"]);
    //the rest of the code goes here as in the example.