Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Date Parsing

Posted on 2010-11-10
Medium Priority
Last Modified: 2012-05-10

How do I parse a date string such the following:

May  6 2010  7:18PM
Apr 30 2010 11:27AM

Into a DateTime?

Question by:mike_pro
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 34103674

DateTime d = Convert.ToDateTime("May  6 2010  7:18PM");


DateTime d;

if (DateTime.TryParse("May  6 2010  7:18PM", out d))
    // d holds the converted date
    // string could not be converted to a date object

Open in new window

LVL 16

Expert Comment

ID: 34104013

You can use DateTime.ParseExact method to specify the exact format (like MMM d yyyy h:mmtt) that you are passing in

DateTime dt = DateTime.ParseExact("May  6 2010  7:18PM", "MMM d yyyy h:mmtt", null)
LVL 10

Expert Comment

ID: 34109825
I use

DateTime dt = DateTime.Parse(Value.Trim(), CultureInfo.GetCultureInfo("nl-NL").DateTimeFormat, DateTimeStyles.AllowInnerWhite | DateTimeStyles.AssumeLocal | DateTimeStyles.NoCurrentDateDefault);

Its parses lots of different formats.

Replace the "nl-NL" by your preferred locale ID.

Regards, Jacco

Author Closing Comment

ID: 34147399

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question