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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:29:32+00:00 2026-06-09T19:29:32+00:00

I am trying to parse a string (from a Textbox filled with english dateformat)

  • 0

I am trying to parse a string (from a Textbox filled with english dateformat) to a DateTime using this code:

DateTime dt;
if (DateTime.TryParseExact(Text, DateTimeFormat, System.Threading.Thread.CurrentThread.CurrentCulture, DateTimeStyles.AssumeLocal, out dt))
{
    logger.Trace("LOCALE: {0} ", System.Threading.Thread.CurrentThread.CurrentCulture);
    logger.Trace("DateTimeFormat: {0} ", DateTimeFormat);
    logger.Trace("CurrentCulture ShortDatePattern: {0} ", System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern);
    logger.Trace("Text: {0} ", Text);
    logger.Trace("result of TryParse: {0} ", dt);
    return dt;
}

However the output in my logger is:

LOCALE: en-US 
DateTimeFormat ShortDatePattern: M/d/yyyy 
CurrentCulture ShortDatePattern: M/d/yyyy 
Text: 8/31/2012 
result of TryParse: 31-8-2012 0:00:00 

I am completly stuck why this is happening.

Using this code in a seperate console application DOES work:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
string text = @"8/31/2012";
DateTime date;
string dateTimeFormat = @"M/d/yyyy";
bool parseOk = DateTime.TryParseExact(text, dateTimeFormat, Thread.CurrentThread.CurrentCulture, DateTimeStyles.AssumeLocal, out date);

extra info:

  • system: Windows 7 Ultimate EN
  • system language for non-UniCode: english
  • web.config system.web:

PROBLEM:
The problem is I want the date to be in the format “M/d/yyyy” but instead it is parsed to “dd-mm-yyyy” which results in an invalid date

  • 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-09T19:29:33+00:00Added an answer on June 9, 2026 at 7:29 pm

    You have not specified an output string for the log entry, so it will use the default one (based on the current culture).

    So, instead of:

    logger.Trace("result of TryParse: {0} ", dt);
    

    Use:

    logger.Trace("result of TryParse: {0} ", dt.ToString("M/dd/yyyy"));
    

    Or:

    logger.Trace("result of TryParse: {0} ", dt.ToShortDateString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a string from a French text, and I'm using both
I'm trying to parse a JSON string using the json library. This code works
I am trying to parse the html_instructions string from the steps array at this
I was trying to parse a JSON string from USGS . However I get
I;m trying to parse a json string which I receive from web server as
Im trying to parse the string located in /proc/stat in a linux filesystem using
I'm trying to parse a string that was generated by an NSDateFormatter using another
I am new to jquery. I am trying to parse xml string using jquery.
I'm trying to parse a int from a String array element. Here is my
I am trying parse out 3 pieces of information from a String . Here

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.