System.Convert.ToDateTime Method

Converts the specified string representation of a number to an equivalent date and time, using the specified culture-specific formatting information.

Syntax

public static DateTime ToDateTime (string value, IFormatProvider provider)

Parameters

value
A string that contains a date and time to convert.
provider
An object that supplies culture-specific formatting information.

Returns

The date and time equivalent of the value of value, or the date and time equivalent of DateTime.MinValue if value is null.

Exceptions

TypeReason
ArgumentException value is a null reference.
FormatException value cannot be converted to a DateTime .

Remarks

The return value is the result of invoking the DateTime.Parse(string, IFormatProvider) method on value.

provider is an IFormatProvider instance that obtains a System.Globalization.DateTimeFormatInfo object. The System.Globalization.DateTimeFormatInfo object provides culture-specific information about the format of value. If provider is null, the System.Globalization.DateTimeFormatInfo for the current culture is used.

If you prefer not to handle an exception if the conversion fails, you can call the DateTime.TryParse(string, DateTime@) method instead. It returns a bool value that indicates whether the conversion succeeded or failed.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0