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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:28:42+00:00 2026-06-14T09:28:42+00:00

i have tried every possible solution online but can’t figure out why i am

  • 0

i have tried every possible solution online but can’t figure out why i am still getting this error
“string was not recognized as valid Date Time”
the funny thing is that i am converting 2 date times, one is cell 3 in my gridview and the other one is cell 7 but the Cell 3 works fine and but Cell 7 does not want to convert and both of them are the same data types!!. I am pulling these data from my sql server table and the data types are varchar but the format should be mm/dd/yyyy.
I have tried this method but it did not work:

foreach (GridViewRow gr in GridView1.Rows)
        {

            CheckBox cb = (CheckBox)gr.FindControl("chkItem");
            if (cb.Checked)
            {

                DateTime ExpectedSubDate = DateTime.Parse(gr.Cells[3].Text);
                DateTime strTargetDate = DateTime.ParseExact(gr.Cells[7].Text, "MM/DD/YYYY HH:MM:SS TT", System.Globalization.CultureInfo.InvariantCulture);  

I have also tried this method but did not work either

DateTime strTargetDate = DateTime.Parse(gr.Cells[7].Text);

I have also tried this way but did not work either:

DateTime strTargetDate = DateTime.ParseExact(gr.Cells[7].Text, "MM/DD/YYYY", System.Globalization.CultureInfo.InvariantCulture);
  • 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-14T09:28:43+00:00Added an answer on June 14, 2026 at 9:28 am

    The format string is case sensetive, otherwise it can’t know where you want it to parse as months or as minutes.

    For a date and time, for example "11/15/2012 02:26:35 PM":

    DateTime strTargetDate = DateTime.ParseExact(gr.Cells[7].Text, "MM/dd/yyyy hh:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture);
    

    For just a date, for example "11/15/2012":

    DateTime strTargetDate = DateTime.ParseExact(gr.Cells[7].Text, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
    

    Ref: Custom Date and Time Format Strings

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried every way I can think of with this, but just not
I have tried every possible solution for my php file 30 seconds timeout, but
I have looked on here and tried every answer available, but it is still
I can't seem to figure this one out. I have a validator-type script that
I have tried every possible combination of methods for replacing an image but have
Well I tried to figure out is this possible in any way. Here is
I have tried every install method I can think of to install RPy2 on
I have tried making every div 75px and the table within the div but
Have tried to find solutions for this and can't really come up with anything.
I am aware that this question has been asked before, but I have tried

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.