How to convert the text value of a textBox into date

Hi,

I have a textBox which contains in its text property a date. I need to place the date into a date variable: I tried without success the following:

Dim newDate As Date = CType(txtNewDate.Text, Date).ToShortDateString

Can you help?

thanks
adamtraskAsked:
Who is Participating?
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Also, if you are not sure if is a valid string date:
        Dim newDate As Date
        If DateTime.TryParse(txtNewDate.Text, newDate) Then
            Console.Write(newDate.ToShortDateString())
        Else
            Console.Write("Sorry can't parse")
        End If

Open in new window

0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hi try:
Dim newDate As Date = DateTime.Parse(txtNewDate.Text)

Then you can use newDate.ToShortDateString()
Or directly DateTime.Parse(txtNewDate.Text).ToShortDateString()
0
 
adamtraskAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.