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?
 
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
 
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]
 
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.
 
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.
 
Back
Top