DateTime.TryParse Method (String, DateTime)
Assembly: mscorlib (in mscorlib.dll)
public static boolean TryParse ( String s, /** @attribute OutAttribute() */ /** @ref */ DateTime result )
A string containing a date and time to convert.
When this method returns, contains the DateTime value equivalent to the date and time contained in s, if the conversion succeeded, or MinValue if the conversion failed. The conversion fails if the s parameter is a null reference (Nothing in Visual Basic), or does not contain a valid string representation of a date and time. This parameter is passed uninitialized.
Return Valuetrue if the s parameter was converted successfully; otherwise, false.
The TryParse method is similar to the Parse method, except that this method does not throw an exception if the conversion fails.
The string s is parsed using the formatting information in a DateTimeFormatInfo object initialized for the current culture.
This method attempts to ignore unrecognized data and parse s completely. It ignores unrecognized data if possible and fills in missing month, day, and year information with the current time. If s contains only a date and no time, this method assumes the time is 12:00 midnight. Any leading, inner, or trailing white space character in s is ignored. The date and time can be bracketed with a pair of leading and trailing NUMBER SIGN characters ('#', U+0023), and can be trailed with one or more NULL characters (U+0000).
The s parameter must contain the representation of a date and time in one of the formats described in the DateTimeFormatInfo class.
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.