DateTimepicker format

nl2ttl

Member
Joined
Nov 9, 2006
Messages
16
Programming Experience
Beginner
How can i get only the date in a variable or textbox from a datetimepicker?
 

tylerwick

Member
Joined
Nov 9, 2006
Messages
7
Programming Experience
1-3
Heres what I did, there might be a another solutuion though

I assigned that to a Button

VB.NET:
lblDate.Text = cal.SelectionEnd
 

tylerwick

Member
Joined
Nov 9, 2006
Messages
7
Programming Experience
1-3
Sorry I was thinking calendar,

try this
VB.NET:
lblDate.Text = DateTimePicker1.Value.Today
It will be in Slash Format, theres a number of things you can do

In Visual Studion a Popup with different Properties will come up when you put in that last period, (After Value)

EDIT:
Value.Date would probably suit you better
 

Raven65

Well-known member
Joined
Oct 4, 2006
Messages
305
Programming Experience
3-5
Just call out the part that you want:

VB.NET:
[SIZE=2]MessageBox.Show([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DateTimePicker1.Value.Date)
[/SIZE]
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
How can i get only the date in a variable or textbox from a datetimepicker?
To get it in the DTP itself, set the format to Custom, and write your own formatting string. To put a customised form of the date into a label or textbox string, use the .Value property of the datetimepicker which will give you the DATE value in the control. You can then ToString() this:

Dim s as String = dtp.Value.ToString("yyyyMMdd")


DO NOT attempt to use this as a date because it is now a string, not a date - if you need the date for something, go back to the dtp and get its value again.
 

Nicezia

New member
Joined
Mar 31, 2009
Messages
1
Programming Experience
Beginner
if you wanted to change the textbox's text back into a date you could Date.Parse(Textbox.Text)
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,319
Location
Sydney, Australia
Programming Experience
10+
you can retrieve it in string also..

Dim idate As String
idate = DateTimePicker1.Value


wgel.
That's very bad code. It would only compile with Option Strict Off for a start. If you wanted a String then you would either get the Text property of the control or else call ToString or the like on the DataTime that you get from the Value property, as has been shown.

Apart from that, please don't resurrect threads that are over four years old without very good reason.
 
Top Bottom