10
Answers

employee hours calculation in c#.

amol

amol

9y
3.7k
1
hello sir i want to calculate total working hours of employee in c#.
 like IN=10:00
        OUT=12:00
        IN:1:00
        OUT:5:00 
   duration=2+5=7;
 below code calculate only last in and out duration i want all in and out dueation time.
 
if (dt1.Rows.Count > 0)
{
for (int j = 0; j < dt1.Rows.Count; j++)
{
DateDay = Convert.ToDateTime(dt1.Rows[j]["emp_ToDate"]);
string st = dt1.Rows[j]["emp_InOut"].ToString();
string time1 = (dt1.Rows[j]["emp_Time"]).ToString();
if (st == ("IN"))
{
Input = Convert.ToString((time1));
}else
if (st == "OUT")
{
Output = Convert.ToString((time1));
}
try
{
duration2 = duration + (DateTime.Parse(Input).Subtract(DateTime.Parse(Output)).Duration());
}
catch { }
}
Answers (10)