= 22:03:00.0000000
My C# Code is below
private void LoadOvertimetotal()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
string str = "SELECT total_sec = SUM(( DATEPART(hh, Overtime_HHMM) * 3600 ) +( DATEPART(mi, Overtime_HHMM) * 60 ) + DATEPART(ss, Overtime_HHMM)) FROM Accounts_DailyAttendance where UserID='" + gvStaffDetails.SelectedRow.Cells[2].Text.ToString().Trim() + "' and datename(month,processdate) ='" + Session["paymonth"] + "' and datepart(yyyy,processdate)='" + Session["payyear"] + "' and Overtime_HHMM<>'00:00:00.0000000'";
string strtotminutes = "SELECT totalovertime = CONVERT(TIME, DATEADD(s, total_sec, 0))FROM Accounts_DailyAttendance";
cmd = new SqlCommand(str, con);
cmd = new SqlCommand(strtotminutes, con);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
lbltotalovertime.Text = reader["totalovertime"].ToString();
reader.Close();
con.Close();
}
Thanks
Thanks

VulpesPosted Oct 29, 2014, 6:11 AM
VulpesPosted Oct 29, 2014, 9:51 AM
cmd = new SqlCommand(str, con);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
int seconds;
int.TryParse(reader["total_sec"].ToString(), out seconds);
TimeSpan ts = TimeSpan.FromSeconds(seconds);
string period;
if(ts.Days == 0)
{
period = ts.ToString(@"hh\:mm\:ss\.fffffff");
}
else
{
period = (ts.Days * 24 + ts.Hours) + ts.ToString(@"\:mm\:ss\.fffffff");
}
lbltotalovertime.Text = period;
Riddhi ValechaPosted Oct 29, 2014, 3:31 AM
I would suggest that you also store a date in separate variable.
Steps-
1.Take a variable and also store the date it in.
2.Instead of converting the C# integer value to date time, just display that variable.
Your code will not be visible to the users.