Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

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
0
adamtrask
Asked:
adamtrask
  • 2
1 Solution
 
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
 
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
 
adamtraskAuthor Commented:
Thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now