Reputation: 140
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 :)
Upvotes: 0
Views: 303
Reputation: 460058
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
.
Upvotes: 4