Search code examples
c#sql-serverwmp

How can I convert HH:MM:SS type to Second?


How can I convert HH:MM:SS Format to Second?

For example I want to turn 01:20:30 into 1 Hr = 3600 Sec + 1200 Sec + 30 Sec = 4830 Sec.

Then I can jump to a specific second on WMP. I want to take mp3 path from MsSQL as you can see. When the form is closed i want to Update the current time from the Database.

Example:

I'm listening to music at this moment, and I'm 03:52 into the track. Then I close the form and re-open music. I want to continue the track at the same time I closed the form (03:52). How can i do that with Ms SQL ?

My current code:

        con.Open();
        SqlCommand cmd = new SqlCommand("select dosyayol from ses", con);
        SqlDataReader oku = cmd.ExecuteReader();
        while (oku.Read())
        {

          pth = oku["dosyayol"].ToString();
        }
        con.Close();
        Player.URL = pth;

Solution

  • var ts = TimeSpan.Parse(pth);
    ts.TotalSeconds();