Nirmal KumarC

Nirmal KumarC

  • 1.1k
  • 327
  • 75.8k

how to Convert integer value to time in c#

Oct 29 2014 2:54 AM
I have i time in Integer = 59400 , how can I convert it in C# to Timeformat
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


Answers (3)