ExtensionMethod.NET Home of 877 C#, Visual Basic, F# and Javascript extension methods


Wraps DateTime.TryParse() and all the other kinds of code you need to determine if a given string holds a value that can be converted into a DateTime object.


public static bool IsDate(this string input)
    if (!string.IsNullOrEmpty(input))
        DateTime dt;
        return (DateTime.TryParse(input, out dt));
        return false;


string nonDate = "Foo";
string someDate = "Jan 1 2010";

bool isDate = nonDate.IsDate(); //false
isDate = someDate.IsDate(); //true

Author: Phil Campbell

Submitted on: 30 mrt. 2010

Language: C#

Type: System.String

Views: 17407