How to change / set the value of DateTimePicker

I am trying to set / change the DateTimePicker value (using vb.net) but cannot decide how to do this.

I added a control to the page, and I tried using the following code, but it does not work, and I cannot decide how to set the value at runtime.

DateTimePicker1.Value = Now.Day & "-" & Now.Month & "-" & Now.Year 

The format of the control is set to Long, and on first boot it looks like this:

Tuesday, February 26, 2013

But I can’t understand how to change it.

The error I am getting is based on my code above:

The conversion from the string "26-2-2013" to enter "Date" is invalid.

Does anyone have any idea?

+7
source share
2 answers

I ended up doing the following:

 DateTimePicker1.Value = New Date(2013, 2, 26) 

I loaded the value incorrectly.

+7
source

Add the following code to the Event Load Event to set the date pick time:

 DateTimePicker1.CustomFormat="dd-MM-yyyy" DateTimePicker1.Value=Now() 
+1
source

All Articles