How to convert the text value of a textBox into date

Posted on 2011-04-22
Last Modified: 2012-05-11

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?

Question by:adamtrask
    LVL 17

    Expert Comment

    by:Carlos Villegas
    Hi try:
    Dim newDate As Date = DateTime.Parse(txtNewDate.Text)

    Then you can use newDate.ToShortDateString()
    Or directly DateTime.Parse(txtNewDate.Text).ToShortDateString()
    LVL 17

    Accepted Solution

    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("Sorry can't parse")
            End If

    Open in new window


    Author Closing Comment

    Thank you

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Title # Comments Views Activity
    Refresh page ASP.NET C# 3 39
    C# primary key 9 46
    Problem to event 3 25
    Adding WebGrid Checkbox Column checked by default 3 13
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now