Solved

Date Parsing

Posted on 2010-11-10
4
498 Views
Last Modified: 2012-05-10
Hi,

How do I parse a date string such the following:

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

Into a DateTime?

Thanks
0
Comment
Question by:mike_pro
[X]
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
4 Comments
 
LVL 75

Accepted Solution

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

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

or

DateTime d;

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

Open in new window

0
 
LVL 16

Expert Comment

by:kris_per
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)
0
 
LVL 10

Expert Comment

by:Jacco
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
0
 

Author Closing Comment

by:mike_pro
ID: 34147399
Thanks
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

631 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