Vishnu
Vishnu

Reputation: 735

how to get dates from text in c#

From a document I want to find and get the dates, and the date will be in a different format in each document. How do I achieve that in C#?

Upvotes: 0

Views: 386

Answers (2)

Adriaan Stander
Adriaan Stander

Reputation: 166486

You should rather have a look at using DateTime.TryParse Method or DateTime.TryParseExact Method

DateTime.TryParse Method Converts the specified string representation of a date and time to its DateTime equivalent and returns a value that indicates whether the conversion succeeded.

DateTime.TryParseExact Method Converts the specified string representation of a date and time to its DateTime equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly. The method returns a value that indicates whether the conversion succeeded.

Upvotes: 4

Rui Jiang
Rui Jiang

Reputation: 1672

Use DateTime.ParseExact(string, format) to create a DateTime from a formatted string.

Check out http://www.codeproject.com/KB/cs/String2DateTime.aspx for more details.

Upvotes: 2

Related Questions