Share via


StringExtensions.AsDateTime Method (String)

Converts a string to a DateTime value.

Namespace:  System.Web.WebPages
Assembly:  System.Web.WebPages (in System.Web.WebPages.dll)

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function AsDateTime ( _
    value As String _
) As DateTime
'Usage
Dim value As String 
Dim returnValue As DateTime 

returnValue = value.AsDateTime()
public static DateTime AsDateTime(
    this string value
)
[ExtensionAttribute]
public:
static DateTime AsDateTime(
    String^ value
)
static member AsDateTime : 
        value:string -> DateTime
public static function AsDateTime(
    value : String
) : DateTime

Parameters

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 pass the method a null reference (Nothing in Visual Basic) value or a string value that cannot be converted to the specified type, it returns a default system date in UTC time. To avoid ambiguity about what the returned value means, call the IsBool(String) method first to check whether the input string can be converted to this type.

See Also

Reference

StringExtensions Class

AsDateTime Overload

System.Web.WebPages Namespace