8

There is a great need for a Robust DateTime parser library for .NET, prefer C# DateTime.TryParse supports very few formats I know the question has been asked a year ago but with no good answer. There must be good libs out there! Commercial or open source

I looked at noda-time. But blog says it does not do parsing yet

Dates fall into two categories:

Date formats: All the various date formats

  • 2011-09-09T20:00:00
  • 29 September 2011
  • 6 September 2011 7:00pm
  • 1/1/2009, 12:00PM

Natural Dates: How a Human would say/write it

  • Today
  • Tomorrrow
  • Mondays, 6PM
  • Every Monday, 6PM
  • Every Friday
  • First Monday of every month
  • Last Sunday of the month
  • Everyday
  • 1st of the Month
svick
  • 236,525
  • 50
  • 385
  • 514
Ben42
  • 105
  • 2
  • 9
  • 2
    I think you either need to wait for Noda Time (parsing is being worked on), or do it yourself. If you contribute to Noda Time you could speed things up... – Richard Sep 04 '11 at 10:57

2 Answers2

10

You can use the C# Date Time Parser of Sergey Stoyan.

  • 1
    Sergey's parser works great. Recommended.All that hassle converted into: `if (DateTimeRoutines.TryParseDate(RawDate, DateTimeRoutines.DateTimeFormat.UK_DATE, out parsedDate))` – Ian Sep 03 '15 at 09:36
  • Fantastic! Just what I was looking for, other than it orders them by "most likely" datetime format, rather than "first", but it's open source, so easy enough to modify. – neminem Aug 24 '17 at 23:21
1

Not sure what you are looking for but I like DateTime.TryParseExact() method.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • 5
    doesn't TryParseExact force you to provide a format yourself? I think the OP wants a library that will do the parsing for you a la DateTime.TryParse but with more features. But yes, you could whip up a parse method using TryParseExact that would cover the cases asked above. – arviman Sep 04 '11 at 06:29
  • @arviman: There is an overload of `TryParseExact` which takes a collection of formats. But inbuilt BCL date time suport will not do "natural dates" as specified by the Q. – Richard Sep 04 '11 at 10:56
  • 1
    The date is comming from a web site or user input and the format is unknown. Parsing a known format is easy detecting and parsing unknown format is very hard. – Ben42 Sep 06 '11 at 00:27