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

  • Home
  • SEARCH
  • 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 7030147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:37:52+00:00 2026-05-28T00:37:52+00:00

datetime parse work exactly when date format is like mm/dd/yyyy but when dateformat is

  • 0

datetime parse work exactly when date format is like mm/dd/yyyy but when dateformat is like dd/mm/yyyy then problem occur. i want to write code to parse date whatever format is used.

suppose if my date is like “15/01/2012” or 05/12/2012 then my code can parse it as valid datetime. so what should i do… i use code like

IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true);
string xxx = DateTime.ParseExact("15/12/2012", "yyyyMMdd", culture).ToString();

it does not work because dateformat is dd/mm/yyyy. so tell me the best solution that when date format would be dd/mm/yyyy or mm/dd/yyyy etc but code can parse it properly. so guide me what code i should use. thanks

  • 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-28T00:37:53+00:00Added an answer on May 28, 2026 at 12:37 am

    You must not allow both MM/dd/yyyy and dd/MM/yyyy formats without any indication of which is used, or you’re just crying out for bad data. What would you interpret “06/05/2011” as? May 6th or June 5th?

    You should either specify the format explicitly or you should use whatever the cultural default is (which shouldn’t allow both formats) – but to treat “13/12/2011” differently from “11/12/2011” just because the day value happens to be 13 is a really bad idea, IMO.

    (The reason your sample code doesn’t work is that you’re explicitly saying you want it parsed as yyyyMMdd, which is clearly not the format of "15/12/2012". I’m not sure why you’d ever expect that to work.)

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

Sidebar

Related Questions

The string I want to format looks like this: String datetime = 9/1/10 11:34:35
I'm trying to parse a date/time string using DateTime.ParseExact . It works everywhere, except
How can I parse a string like 01-Jan-1995 to a Python datetime object?
I'm trying to Parse dates entered into a TextBox into a DateTime value but
I read other threads like this but they didn't work for me. I got
I have following code: string date = 13.04.2012; string date2 = (DateTime.Parse(date).AddDays(1)).ToString(); This is
in this site It is very strange. DateTime a = DateTime.Parse(5/26/2011); Response.Write(a.ToShortDateString()); this code
Which of the following is better code in c# and why? ((DateTime)g[0][MyUntypedDateField]).ToShortDateString() or DateTime.Parse(g[0][MyUntypedDateField].ToString()).ToShortDateString()
I was wondering what is the best way to parse a DateTime object to
Are there any existing libraries in existence that will parse a datetime from a

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.