Question String to date

tqmd1

Well-known member
Joined
Dec 5, 2009
Messages
60
Programming Experience
Beginner
Dear Sir.

I use following codes to to convert string to date.
In messagebox it displays correct date with format but in textbox it displays only #12:00:00 AM #
How to send date to textbox1 from variable mydate
Please help

VB.NET:
 Dim mydate As Date
        Dim dateString = "31/12/2009"
        Dim formats As String() = {"dd/MM/yyyy", "dd/MM/yyyy"}
        Dim dateObject As DateTime = DateTime.ParseExact(dateString, formats, System.Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.NoCurrentDateDefault)
        MessageBox.Show(dateObject.ToString("dd/MM/yyyy"))
        Me.TextBox1.Text = mydate
 
You're creating a date object 'mydate' which you never initialize and then assign to TextBox1.Text. In the MessageBox you're showing 'dateObject' which you set in the line above.
 
Back
Top