StringExtensions.AsDateTime Method (String, DateTime)
Converts a string to a DateTime value and specifies a default value.
Namespace: System.Web.WebPages
Assembly: System.Web.WebPages (in System.Web.WebPages.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function AsDateTime ( _
value As String, _
defaultValue As DateTime _
) As DateTime
'Usage
Dim value As String
Dim defaultValue As DateTime
Dim returnValue As DateTime
returnValue = value.AsDateTime(defaultValue)
public static DateTime AsDateTime(
this string value,
DateTime defaultValue
)
[ExtensionAttribute]
public:
static DateTime AsDateTime(
String^ value,
DateTime defaultValue
)
static member AsDateTime :
value:string *
defaultValue:DateTime -> DateTime
public static function AsDateTime(
value : String,
defaultValue : DateTime
) : DateTime
Parameters
- value
Type: System.String
The value to convert.
- defaultValue
Type: System.DateTime
The value to return if value is null reference (Nothing in Visual Basic) or is an invalid value. The default is the minimum time value on the system.
Return Value
Type: System.DateTime
The converted value.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see https://msdn.microsoft.com/en-us/library/bb384936(v=vs.111) or https://msdn.microsoft.com/en-us/library/bb383977(v=vs.111).
Remarks
For more information about how to use this method, see the AsDateTime() topic. If you think that your code might be passed null reference (Nothing in Visual Basic) or a string value that cannot be converted to the specified type, you can use the AsDateTime overload to return a specified DateTime value instead of the default time value (1/1/0001 12:00:00 AM).