Ads Top

Convert String to DateTime

In .Net Framework, you can work with date and time easily using the DateTime class. You can use the methods like Convert.ToDateTime(String), DateTime.Parse() and DateTime.ParseExact() methods for converting a string-based date to a System.DateTime object.


Convert.ToDateTime(String)

This method will converts the specified string representation of a date and time to an equivalent date and time value

C#


string iDate = "05/05/2005";
DateTime oDate = Convert.ToDateTime(iDate);
.ShowMessageBox(oDate.Day + " " + oDate.Month + "  " + oDate.Year );

VB.Net

Dim iDate As String = "05/05/2005"
Dim oDate As DateTime = Convert.ToDateTime(iDate)
MsgBox(oDate.Day & " " & oDate.Month & "  " & oDate.Year

No comments:

Powered by Blogger.