locked
Converting a textbox to DateTime RRS feed

  • Question

  • User206383436 posted

    I have a textbox that contains a date and I want to convert it to a date type, so I am using Convert.ToDateTime(txtDate.Text) but the result I get is the date plus a time, like this: 07/11/2010 12:00:00 a.m.

    What can I do to get only the date part without the time?

    With respect,
    Jorge Maldonado

    Thursday, January 6, 2011 7:07 PM

Answers

  • User-158764254 posted

    the Date datatype will always include the time.

    it's usually when you are displaying that date (as text) that you format it to either include the time or not 

    for example:

    someDateString =  myDate.ToShortDateString

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 6, 2011 8:00 PM
  • User-1757793930 posted

    A datetime object will always have the Time portion, you can not get rid of the time.

    However you can format the datetime to display as a string without the date portion using .ToDateString(), .ToShortDateString(), or .ToString('<format options')


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 6, 2011 8:02 PM

All replies

  • User-158764254 posted

    the Date datatype will always include the time.

    it's usually when you are displaying that date (as text) that you format it to either include the time or not 

    for example:

    someDateString =  myDate.ToShortDateString

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 6, 2011 8:00 PM
  • User-1757793930 posted

    A datetime object will always have the Time portion, you can not get rid of the time.

    However you can format the datetime to display as a string without the date portion using .ToDateString(), .ToShortDateString(), or .ToString('<format options')


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 6, 2011 8:02 PM
  • User988538322 posted

    Hi Jorgemal Hope you are fine


    dim dDate as Date

    TextBox1.Text = "2/2/2010"

            dDate = TextBox1.Text

            TextBox2.Text = Format(dDate, "MMMM dd, yyyy")

            TextBox3.Text = Format(dDate, "MM/dd/yyyy")

    and the Result is

    textbox2.text is show in "February 02, 2010"

    textbox2.text is show in "02/02/2010"

    and its a format Types


    http://www.sql-server-helper.com/tips/date-formats.aspx

    Hope it will help you

    Friday, January 7, 2011 1:55 AM
  • User-1798199798 posted

    You can add one more line to your code and thats it :)


    dim Dt as date=Convert.ToDateTime(txtDate.Text)

    Dt=Date.Parse(Dt.ToString("ddMMyyyy"))

    Saturday, January 8, 2011 10:27 AM