Click or drag to resize
DateTimeTryParse Method (String, IFormatProvider, DateTimeStyles, DateTime)
Converts the specified string representation of a date and time to its DateTime equivalent using the specified culture-specific format information and formatting style, and returns a value that indicates whether the conversion succeeded.

Namespace: System
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public static bool TryParse(
	string s,
	IFormatProvider provider,
	DateTimeStyles styles,
	out DateTime result
)

Parameters

s
Type: SystemString
A string containing a date and time to convert.
provider
Type: SystemIFormatProvider
An object that supplies culture-specific formatting information about s.
styles
Type: System.GlobalizationDateTimeStyles
A bitwise combination of enumeration values that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is None.
result
Type: SystemDateTime
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 null, is an empty string (""), or does not contain a valid string representation of a date and time. This parameter is passed uninitialized.

Return Value

Type: Boolean
true if the s parameter was converted successfully; otherwise, false.
Exceptions
ExceptionCondition
ArgumentExceptionstyles is not a valid DateTimeStyles value.-or-styles contains an invalid combination of DateTimeStyles values (for example, both AssumeLocal and AssumeUniversal).
ArgumentOutOfRangeExceptionThe date is in Japanese Emperor Year (Wareki) format and the year is out of range.
NotSupportedExceptionprovider is a neutral culture and cannot be used in a parsing operation.
See Also