Take the 2-minute tour ×

I have a lot of different date format that one of my field can contain. And I'm trying to parse it but it some times doesn't understand the format at all and returns 1900-01-01. Or sometimes, it invert months, days and year: 2023-12-11 instead of 2012-11-23.

The field is contained in a total of 1500-2500 excel files, that are produced by some kind of scanner. Dates and time are in different cases.

I've seen different formats such as these so far: yyyy-mm-dd or mm/dd/yy and some others (that i cant find because i dont want to spend the day oppenning random excel files hoping to find a different format ^^')

So... I've tried parsing it at hand (Substring of the different fields), but it still has bugs, so:

Is there any date parsing tool for VB that works often?

I imagine there is a library or something that can parse dates from almost any format already coded, and if I could avoid to recode it I'd be quite happy :)

share|improve this question
Why are you asking for efficient? I would ask for anything that works for all of your unknown formats instead. –  Tim Schmelter Jan 28 '13 at 16:27
DateTime.ParseExact allows you to specify the exact formatting of the input string. You'll still need to be able to determine the correct format string to give it, though. –  Steven Doggart Jan 28 '13 at 16:27
I'm not asking for something that works every time ... I meant efficient as works often. –  Ludovic Migneault Jan 28 '13 at 16:44
add comment

1 Answer

No, of course there is nothing that can parse dates in any (unknown) format. How should it know what to do with 9/10/11? That can be anything.

So you can use TryParse or TryParseExact (you can even pass a string[] for multiple allowed formats) and pass the correct CultureInfo.

share|improve this answer
I'm already using those. What I ask for isn't something that always works, just something that works often... And if this doesn't exist yet, it SHOULD! because there is a lot of conventions for dates, usually the date formats stays within a certain order. As for 10/10/10, it usually is month day, year no? and 2012-01-01 is yyyy-mm-dd not yyyy-dd-mm, it's just conventions, a library as I ask for would just try every formats from the more plausible to the less while parsing... –  Ludovic Migneault Jan 28 '13 at 16:48
add comment

Your Answer


