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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:22:12+00:00 2026-06-01T23:22:12+00:00

I try to convert string to datetime but each time I get : String

  • 0

I try to convert string to datetime but each time I get :

String was not recognized as a valid DateTime.

Code is:

string format = "dd/MM/yyyy";

obj.TransDate = DateTime.ParseExact(lbl_TransDate.Text.Split('/')[0] + "/" + lbl_TransDate.Text.Split('/')[1] + "/" + lbl_TransDate.Text.Split('/')[2], format, CultureInfo.InvariantCulture);

When I debug the date which I try to parse it is : 12/4/2012

  • 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-01T23:22:13+00:00Added an answer on June 1, 2026 at 11:22 pm

    The desired format is

    string format = "dd/M/yyyy";
    

    I don’t understand a thing though, why split an concatenate the string, since you would obtain the same thing?

    If the input is 12/4/2012, after the split by ‘/’, you’ll get 12, 4, 2012 and then concatenate them back to obtain “12/4/2012”. Why this?

    Also, if you really need that split, you can store in into an array so you don’t need to split it 3 times:

    var splits = lbl_TransDate.Text.Split('/');
    DateTime.ParseExact(splits[0] + "/" + splits[1] + "/" + splits[2], ...);
    

    If you don’t trust the input, the splits array might not be of Length = 3, and more of it, you can use DateTime.TryParseExact

    EDIT You can use the overload with multiple formats
    So if the input might be 12/4/2012 or 12/04/2012, you can give both formats

    var formats = new[] {"dd/M/yyyy","dd/MM/yyyy"};
    var date = DateTime.ParseExact("12/4/2012", formats, 
                                            System.Globalization.CultureInfo.InvariantCulture,
                                            System.Globalization.DateTimeStyles.AssumeLocal);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to convert string type dd.MM.yyyy HH:mm:ss.mmm to the datetime using the way
In Java you can try to convert any String value to Integer, but when
When I try to convert between date and string in Flash CS4, I use
When I try to convert an HTTP POST response to JSONArray I get the
how do i convert the following datetime string that contains a timezone designation into
I have a string that is a valid date but it is a string
I have datetime data in string format like this: Sat Mar 24 23:59:59 GMT
I'm trying to put a variable, stored in a string format in a dateTime
I want to convert text to datetime but having error.My text box value is
This is going to sound very silly but I can't get a string to

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.