Datatype time MySQL vs aspx page in cs RRS feed

  • Question

  • User314352500 posted


    On MySQL table it's memorize this value on column sTime datatype time (HH:mm:ss)


    This value is a time difference between two start and end dates

    2020-06-19 23:11:10 Start date 
    2020-06-20 23:31:44 End date

    For recovery this value 24:20:34 on aspx page I have inserted

    tx2.Text = reader["sTime"].ToString().ToUpper();

    But the return on the browser is


    I have tried without success

        DateTime HHMMSS = Convert.ToDateTime(reader["sTime"]);
        tx2.Text = HHMMSS.ToString("HH:mm:ss");

    How to do resolve this?

    Can you help me, please?

    Monday, June 22, 2020 9:22 AM


  • User-939850651 posted

    Hi Uncle Vince,

    To calculate the time difference between two dates and times, many people use the TimeSpan Struct to solve it.

    But if you use the TimeSpan Class, the part whose hour exceeds 23 will be converted to days by default.

    Therefore, I think you have to use a string to display it. Please see the code below:

    public static void Main()
                DateTime dt = new DateTime(2020, 6, 19, 23, 11, 10);
                DateTime dt2 = new DateTime(2020, 6, 20, 23, 31, 44);
                TimeSpan ts = dt2.Subtract(dt);
                String TimeDiff = format(ts.Days * 24 + ts.Hours)+":"+format(ts.Minutes)+":"+format(ts.Seconds);
                //DateTime dateTime = Convert.ToDateTime(TimeDiff);
            public static String format(int data) {
                if (data < 10) return "0" + data.ToString();
                return data.ToString();


    Hope this can help you.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 23, 2020 6:37 AM