Home  »  Forum  »  ASP.Net  »

Need to Calculate the total working hours for a particular employee

 Posted By : celv celvPosted Date : 19/10/2014 10:58:57 PM Category : ASP.Net Points : 2

string constr = ConfigurationManager.AppSettings["s"].ToString();
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT CONVERT(VARCHAR(10),InTime,108 ), CONVERT(VARCHAR(10),outTime,108 ) FROM aten WHERE Id = '" + txtid.Text + "' and date between ' " + Session["fromdate"].ToString() + "' and '" + Session["todate"].ToString() + "'", conn))
{
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
TimeSpan i = new TimeSpan(0, 0, 0);
while (sdr.Read())
{
DateTime inTime = Convert.ToDateTime(sdr[0].ToString(), new CultureInfo("en-Gb"));
DateTime outTime = Convert.ToDateTime(sdr[1].ToString(), new CultureInfo("en-Gb"));
i += outTime.Subtract(inTime);
double hours = i.Hours + (i.Days * 24);
string time = string.Format("{0} : {1}", hours, i.Minutes);
this.txthourswrk.Text = time; 

conn.Close();
}




my data is
id      intijme            outtime
3      09:10:35      20:33:12
3     08:58:17       20:26:26
3     09:31:50       20:33:33


my output is
Total Hours = 9:52:29

it never show above one hour.i need to show 33 hours 52minutes 
Responses
Post Reply
Login to post Response.