WayneSpangler

I want 1/20/2007. I get 1/20/2007 4:44:45 AM. Here is the code I'm using:

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged

Dim dt As DateTimePicker = sender

Dim str As String

'TextBox1.Text = Format$("{0:d}", dt.Value.ToString)

'TextBox1.Text = Format$("{0:M d,yyyy}", dt.Value.ToString)

'TextBox1.Text = Format$("{0:m d,yyyy}", dt.Value.ToString)

'str = Format$("{0:m d,yyyy}", dt.Value)

str = dt.Value.ToString

TextBox1.Text = str.Substring(0, InStr(str, " ") - 1)

End Sub

As you can see I have tried several ways but the time shows up in all but manualy taking the time out. As a matter of fact I don't even need the format to show the date like I want it. Or should I not use the datetimepicker at all, maybe something else

I have thought about setting up a dialog box where the month, day and year can be selected and returned like I want.




Re: Visual Basic Express Edition Why does time show in Format$

jo0ls

dt.Value.ToShortDateString




Re: Visual Basic Express Edition Why does time show in Format$

SJWhiteley

Stop using the old format functions and format using the String.Format method:

Dim dt As DateTime = #1/20/2007#

str = String.Format("{0:M/d/yyyy}", dt)

Debug.WriteLine(str)

' or

str = String.Format("{0:MM/dd/yy}", dt)

Debug.WriteLine(str)

' etc...






Re: Visual Basic Express Edition Why does time show in Format$

WayneSpangler

Stephen,

I already tried it using the String.Format and System.String.Format.

joOls solution worked but I don't know why the others won't. Besides what I showed I tried 6 or 8 other ways. I am going to try it on my other computer to see if it might be the problem. I am working on a laptop right now.

P.S. I didn't even see the ToShortDateString. DUH.






Re: Visual Basic Express Edition Why does time show in Format$

duck thing

Replace

TextBox1.Text = Format$("{0:m d,yyyy}", dt.Value.ToString)

with

TextBox1.Text = dt.Value.ToString("m d, yyyy")

Does this help The ToString method is very versatile






Re: Visual Basic Express Edition Why does time show in Format$

SJWhiteley

Well, what I posted works just fine.




Re: Visual Basic Express Edition Why does time show in Format$

duck thing

SJWhiteley wrote:
Well, what I posted works just fine.

Don't know how I missed that. Sorry.






Re: Visual Basic Express Edition Why does time show in Format$

SJWhiteley

Hmmmm...I didn't think I replied to you. Strange.

Anyway...the String.Format method and the .ToString method take similar (Y/M/d, etc.) formatting arguments and can be interchanged for simple formatting of a single value. And in this case, I think I'd prefer the .ToString as Duck Thing posts.