CDate Function in VB.NET

How to convert a String to Date in VB.Net?

Explanation

CDate Function - Convert String to Date

CDate Function in Visual Basic.net 2008 is used convert an expression into Date datatype. The whole expression is considered for converting to Date datatype.
Syntax:

CDate(expression)
Example:

Module Module1
Sub Main()
Console.WriteLine("December 07 1976, converted to
Date Datatype is::"& CDate("December 07, 1976"))
Console.ReadLine()
End Sub
End Module
Result:

December 07 1976, converted to Date Datatype is:: 12/7/1976

In the above example, the string is converted into date datatype.

Visual Basic Tutorial


Ask Questions

Ask Question