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 8809413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:52:14+00:00 2026-06-14T02:52:14+00:00

I have a DataTable dtTest . I want to parse one cell from this

  • 0

I have a DataTable dtTest.

I want to parse one cell from this table from row 2 and colum 2
This cell can have a format of hh:mm:ss or h:mm:ss

I want to parse it to switch to format h.mm or hh.mm

here I verify if there is symbol “:” or not on position 2

string typeTime = dtTest.Rows[2][2].ToString().Substring(1, 1);

Now I parse them:

TimeSpan.ParseExact(dtTest.Rows[2][2].ToString(), 
    typeTime == "." ? "h'.'mm" : "hh'.'mm", CultureInfo.InvariantCulture);

After parsing it gives me an error “Input string was not in a correct format“.

  • 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-06-14T02:52:15+00:00Added an answer on June 14, 2026 at 2:52 am

    You are trying to parse a string exactly – your string contains a seconds component that does not exist in your format strings. Your string also contains : where you specify ..

    The following should work:

    TimeSpan.ParseExact(dtTest.Rows[2][2].ToString(), 
        "h':'mm':'ss", CultureInfo.InvariantCulture);
    

    Note that the h format specifier will correctly understand 8 or 08.

    Additionally, you can simply use one of the standard TimeSpan format strings – specifically g OR c instead of the custom format string:

    TimeSpan.ParseExact(dtTest.Rows[2][2].ToString(), 
        "g", CultureInfo.InvariantCulture);
    
    TimeSpan.ParseExact(dtTest.Rows[2][2].ToString(), 
        "c", CultureInfo.InvariantCulture);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datatable where I want to change the color of a cell
I have a DataTable which is generated from .xls table. I would like to
I have a datatable loaded from a table of a database that contains elements
I have this datatable, actually a list of datatable List<DataTable> lstDataSource , now for
I have a datatable and want it to export it to excel file, it
I have datatable table like id name address phoneno 1 abc kfjskl 798798 2
I have dataTable in my page. Initially I want it to be hidden, and
I have datatable in vb.net 2008 has 40000 rows. i want to delete 1000
I have DataTable with same structure in SqlServer DB Table. To save data in
I have a DataTable object that contains all the data for a Table visualization.

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.