Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3695346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:36:24+00:00 2026-05-19T04:36:24+00:00

I have HH:mm:ss from database with HH is more than 100. I have data

  • 0

I have HH:mm:ss from database with HH is more than 100.
I have data like that for about 3 rows.

I want to calculate the total show in HH:mm:ss.

So, I split that HH:mm:ss to second and I get total second. And I work like this.

TimeSpan t = TimeSpan.FromSeconds(TTTot); 
string answer="";
answer = string.Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds);
answer = string.Format("{0:D2}-{1:D2}:{2:D2}:{3:D2}", t.Days, t.Hours, t.Minutes, t.Seconds);    
answer = string.Format("{0:D5}:{1:D2}:{2:D2}",t.TotalHours, t.Minutes, t.Seconds);

The first line of the answer is my original code. I only saw around 15 hours while there are around 130 in total values.

So I upgraded to second line of answer which shows together with day. That works.

However, I would like to show total hour. So i modify the code to the third line where I get the exception as

Invalid format exception

I wonder how to twist to get the result I want. HH:mm:ss with HH may b in hundred values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:36:25+00:00Added an answer on May 19, 2026 at 4:36 am

    This MSDN Library page is very relevant. It says this about the D or d format specifier:

    The “D” (or decimal) format specifier
    converts a number to a string of
    decimal digits (0-9), prefixed by a
    minus sign if the number is negative.
    This format is supported only for
    integral types
    .

    Which is a problem, TimeSpan.Hours returns a double value, not an integral value, like TimeSpan.Minutes does. You can fix this problem by truncating (not rounding) the double value, like this:

    answer = string.Format("{0:D5}:{1:D2}:{2:D2}",
       (int)t.TotalHours, t.Minutes, t.Seconds);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to retrieve the more than 100 records from the Database table using
I have taken the data from database into array now I want it to
I have 3 static data tables with more than 100 thousand records. This tables
We have a operation in which more than 100.000 records are read from a
I have data coming from the database in the form of a DataSet .
I have a DataTable which I select from database (Well, these data cross several
I have a treeview control on an aspx page. The data comes from database
I have a problem using the SSIS. I try to import data from database
I want to store more than 1000 character in database, I use MySQL database.
I have a simple data set, a few collections, not more than 20 documents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.